Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

iPhone PopToRootViewController and immediately push a new view controller

Why is the following iPhone code not working:

[self.navigationController popToRootViewControllerAnimated:NO];
LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"TableView" bundle:nil] autorelease];
[self.navigationController pushViewController:loginViewController animated:YES];

The above code causes the rootviewcontroller to be shown (not animated) but the new viewcontroller is not showing up. Is the above code wrong? How am I supposed to do the described?

Mac Mini, Mac OS X (10.5.6)

Posted on Jan 19, 2010 1:19 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 19, 2010 10:01 PM

Try
UINavigationController * navigationController = self.navigationController;
[navigationController popToRootViewControllerAnimated:NO];
LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"TableView" bundle:nil] autorelease];
[navigationController pushViewController:loginViewController animated:YES];

I think your bit of code comes from a view controller which is in the navigation stack, so the popToRootViewControllerAnimated: message set the navigationController property to nil, thus the pushViewController:animated: message is sent to nil.
2 replies
Sort By: 
Question marked as Top-ranking reply

Jan 19, 2010 10:01 PM in response to Basta

Try
UINavigationController * navigationController = self.navigationController;
[navigationController popToRootViewControllerAnimated:NO];
LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"TableView" bundle:nil] autorelease];
[navigationController pushViewController:loginViewController animated:YES];

I think your bit of code comes from a view controller which is in the navigation stack, so the popToRootViewControllerAnimated: message set the navigationController property to nil, thus the pushViewController:animated: message is sent to nil.
Reply

iPhone PopToRootViewController and immediately push a new view controller

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.