I have a tab bar controller into a navigation controller. I want to change the navigation controller's root view depending on whether or not a user is logged in. How do I do this? I don't want to put the code in didFinishLaunchingWithOptions:
or any other AppDelegate method because it won't be the first thing the users will see.
Asked
Active
Viewed 519 times
1

Richard McCluskey
- 588
- 6
- 16
-
See this: [http://stackoverflow.com/questions/6717260/iphone-replacing-rootview-in-navigation-controller][1] [1]: http://stackoverflow.com/questions/6717260/iphone-replacing-rootview-in-navigation-controller – ddevaz Aug 12 '13 at 23:10
-
In the first answer, I do not know what this array contains. `setViewControllers:[NSArray arrayWithObject:detailViewController]` – Richard McCluskey Aug 13 '13 at 03:41
1 Answers
1
You're right, its supposed to be:
- (void) goNext {
NextViewController* nextWindow = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
[self.navigationController setViewControllers:[NSArray arrayWithObject:nextWindow] animated:YES];
}
Since you can't pop the root view controller, the following method can be used instead:
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
Here's a link to the apple docs for this method.

ddevaz
- 2,253
- 1
- 17
- 10
-
So I put in the goNext code as this `NextViewController* nextWindow = [[NextViewController alloc] init]; [self.navigationController setViewControllers:[NSArray arrayWithObject:nextWindow] animated:YES];` since I am using storyboards and not Nibs, but when it changes ViewControllers, the screen is black. It doesn't have the buttons or any other UIElements I put in. – Richard McCluskey Aug 13 '13 at 17:26
-
I found the problem. Since I am using Storyboards, this code worked for me. `- (void) goNext { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; NextViewController* nextWindow = [storyboard instantiateViewControllerWithIdentifier:@"NextView"]; [self.navigationController setViewControllers:[NSArray arrayWithObject:nextWindow] animated:YES]; }` – Richard McCluskey Aug 13 '13 at 17:45
-
cool, glad you got it to work. Yes, I should have mentioned that re-instantiating the controller is necessary when using storyboards. – ddevaz Aug 13 '13 at 17:51