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

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

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.