It turns out that what I want to do is that when I come from a 3d shortcut, forcing the UITabBarController
to choose an index, if I do this in the tab bar viewDidAppear()
the problem is that the viewDidAppear()
of my main UIViewController
Embedded is not called, if I click again on the tab bar item then already if it is called. With the rest of the drivers does not happen, I understand why it is not the one that is first in the list of items in the UITabBarController
.
Tab bar controller: (Here it comes)
override func viewDidAppear(_ animated: Bool) {
if goTasks {
self.selectedIndex = 0
} else if goTodo {
self.selectedIndex = 2
} else if goProjects {
self.selectedIndex = 3
} else if goSearch {
self.selectedIndex = 0
}
}
My first UIViewController
:
(Not called this method)
override func viewDidAppear(_ animated: Bool) {
print("Entry")
}
Is the problem override
the methods? Any solution?
The Simple Answer. The technical reason for when viewWillAppear gets called is simple. Notifies the view controller that its view is about to be added to a view hierarchy. It can't be any view hierarchy — it has to be the one with a UIWindow at the root (not necessarily the visible window).
viewWillAppear(_:)Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.
viewDidAppear is called once you see the loaded view on screen. It is called after view appeared.
The method viewWillAppear: is triggered in response to a change in the state of the application, indicating that the view controller is becoming “active.”
In your UITabBarController class viewDidAppear func , call it's super class, like this
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if goTasks {
self.selectedIndex = 0
} else if goTodo {
self.selectedIndex = 2
} else if goProjects {
self.selectedIndex = 3
} else if goSearch {
self.selectedIndex = 0
}
}
After that, your first viewcontroller will call this method.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("Entry")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With