简体   繁体   中英

accessing multiple navigation controllers in a tab bar controller

I had one nav bar controller, which I embedded in a tabbar controller. I then put two more nav bar controllers onto the story board and created push segues from the tab bar controller to the two new navbar controllers, so I expected the log statement below to be 3, for the number of view controllers on the tab bar controller, however, it logged 1. The last line of code below also obviously threw an out of bounds error because there is no objectAtIndex:1 . Can you explain? Why aren't the second and third navbar controllers that I created push segues to in storyboard present in the viewControllers property of the tab bar controller?

UITabBarController *tbc = (UITabBarController *)self.window.rootViewController;
NSLog(@"tbc %lu", (unsigned long)[[tbc viewControllers] count]);
UINavigationController *nav = (UINavigationController *)[[tbc viewControllers] objectAtIndex:0];
UINavigationController *nav2 = (UINavigationController *)[[tbc viewControllers] objectAtIndex:1];

The problem was that when I connected the tab bar controller to the 2nd and 3rd navigation controller in the storyboard, I created a "push" segue. However, it has to be a "relationship" segue between the tab bar controller and whatever view controllers it's connected to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM