0
votes

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];
1
What is the problem ?A-Live
@A-Live sorry if it wasn't clear, I updated the OPBrainLikeADullPencil
Ehm, whenever you have a UITabBarController at your app it must be a root view controller. Ok, I see the problem now, why don't you use viewControllers property of the UITabBarController ?A-Live
@A-Live ok thanks for that, but can you look at the update to the OP? I added two more nav bar controllers and connected them with push segues to the tab bar controller, but the count of the viewControllers property on the tab bar controller is only 1 for the first nav bar controller that I put on the story board (which I embedded in the tab bar controller).BrainLikeADullPencil

1 Answers

1
votes

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.