Reputation: 6769
Just created a new project and I have 4 view controllers which I add to UINavigationController
like this:
WatchViewController *first = [[WatchViewController alloc] init];
BetViewController *second = [[BetViewController alloc] init];
Settings *third = [[Settings alloc] init];
Account *forth = [[Account alloc] init];
UINavigationController *navFirst = [[UINavigationController alloc]initWithRootViewController:first];
UINavigationController *navSecond = [[UINavigationController alloc]initWithRootViewController:second];
UINavigationController *navThird = [[UINavigationController alloc]initWithRootViewController:third];
UINavigationController *navForth = [[UINavigationController alloc]initWithRootViewController:forth];
Load them into an array:
NSArray *viewArray = [[NSArray alloc] initWithObjects:navFirst, navSecond, navThird, navForth, nil];
Load the tab bar and window:
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewArray animated:YES];
[self.window setRootViewController:self.tabController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
All the view are just standard views. When I try and run the app it responds with :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
I can't figure out what I've missed. Any help?
Upvotes: 0
Views: 287
Reputation: 6769
Sorry, I had annoyingly subclassed UINavigationController instead of UIViewController. I hadn't picked up on it because if I didn't use the NavControllers the App would run fine, add the nav controllers and it broke. :(
Upvotes: 0
Reputation: 13546
Why don't you try UINavigationController
inside UITabBarController
by setting controllers in xib. It worked for me.
Upvotes: 1
Reputation: 744
Try this one:
WatchViewController *first = [[WatchViewController alloc] initWithNibName:@"WatchViewController" bundle:Nil];
BetViewController *second = [[BetViewController alloc] initWithNibName:@"BetViewController" bundle:Nil];
Settings *third = [[Settings alloc] initWithNibName:@"Settings" bundle:Nil];
Account *forth = [[Account alloc] initWithNibName:@"Account" bundle:Nil];
/*Your View Navigation Stuff and your viewArray*/
self.tabController.viewControllers = viewArray;
Upvotes: 1
Reputation: 8928
Don't create 4 navigation controllers. Controllers that are needed to navigate through should be assigned to viewControllers
property in UINavigationController
via setViewControllers:animated:
method.
You should create 1 NavigationController and add array of 4 UIViewControllers.
A very good example is given here: example and don't forget to look here UINavigationClass
Upvotes: 1