[ACCEPTED]-How to get the 'current' navigation controller from tab bar controller-uitabbarcontroller
Accepted answer
Use the UITabBarController
s selectedViewController property.
navcon = (UINavigationController*)myTabBarController.selectedViewController;
[navcon pushViewController:someViewController animated:YES];
0
I think UITabBarController selectedViewController
property should be what you are 2 looking for.
So, from a UITabBarController 1 method :-
[self.selectedViewController pushViewController:someViewController animated:YES];
Updating Starsky's Swift answer to iOS 13 2 ("'keyWindow' was deprecated in iOS 1 13.0")
guard let tabBarVC = UIApplication.shared.windows.filter({$0.isKeyWindow}).first?.rootViewController as? UITabBarController else { return }
if let currentNavController = tabBarVC.selectedViewController as? UINavigationController {
...
}
A Swift version, in case someone can't read 4 Objective-C, with an additional solution 3 for how to find the tabBar from anywhere. I 2 use this to push to a screen when processing 1 a notification.
guard let tabBarVC = UIApplication.shared.keyWindow?.rootViewController as? UITabBarController else { return }
if let currentNavController = tabBarVC.selectedViewController as? UINavigationController {
currentNavController.pushViewController(someVC, animated: true)
}
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.