I am writing a code in which I have a view controller with certain tabs. Upon the dismissal of a an alert, I want open 2nd tab automatically. For this purpose I posted a local notification when the alert this dismissed. The observer for this notification is in home view controller, when this observer is called, 2nd tab of the view controller is selected. Here is my code for a better understanding:
vc.dismiss(animated: true, completion: {
// vc is the view controller in which my custom alert is shown
NotificationCenter.default.post(name: NSNotification.Name.OpenConsumerTab,
object: ConsumerHomeTab.Stats.rawValue)
})
And home view controller: (question related code)
NotificationCenter.default.addObserver(self,
selector: #selector(onOpenConsumerTabNotificationRecieved(notification:)),
name: Notification.Name.OpenConsumerTab,
object: nil)
@objc public func onOpenConsumerTabNotificationRecieved(notification: Notification) {
if (notification.object as! Int == ConsumerHomeTab.Stats.rawValue)
{
selectedIndex = 1
}
}
This is opening the tab but the output I am obtaining is this: (getting an extra black bar)
Why is this happening? Maybe it is showing up a completely new home view controller (with tab bar) but what is the reason? Correct me if I am wrong as I am newbie to iOS.
Things I have tried:
Get the root view controller (home view controller) and select its tab but the output was same.
Using pop view controller but it opens up first tab (index 0) but my requirement is to open the second tab (index 1)