Reputation:
So I'm trying to pop a view controller off the stack when an error occurs, but it seems like it's popping too much off in one go. The navigation bar up the top loses its title and buttons, but the old table view data remains visible. I have no idea what's going on...
The basic set up is:
Here's the code:
NSLog(@"%@", [[self navigationController] viewControllers]);
[[self navigationController] popViewControllerAnimated:NO];
NSLog(@"%@", [[self navigationController] viewControllers]);
The resulting NSLog's show:
2009-09-22 19:57:14.115 App[34707:550b] (
<MyViewController: 0xd38a70>,
<MyViewController: 0xd36b50>
)
2009-09-22 19:57:14.115 App[34707:550b] (null)
Anyone have experience with this?
Upvotes: 3
Views: 26348
Reputation: 61
I am seeing some odd UINavigationController
stack behavior with just using
[self.navigationController popViewControllerAnimated:YES];
inside of a delegate called out of a tableView:didSelectRowAtIndexPath:
call.
The views don't work right, and a UINavigationController
provided "back" operation doesn't correctly pop the view of this delegate, going back another level.
I found that if I used
[self.navigationController popToViewController:self animated:YES];
instead, that suddenly everything worked fine. This is in an application with ARC turned on.
So, I can only guess that there is some reference housekeeping that doesn't happen correctly unless you tell it to pop back to a specific view controller when you will pop a view controller that will immediately become "unreferenced" by that pop.
Upvotes: 4
Reputation: 21760
What is wrong with?
[self.navigationController popViewControllerAnimated:NO];
Also, you may want to check how you push the ViewController
onto the stack. Something doesn't sound right.
Upvotes: 0
Reputation: 6263
[[self navigationController] popViewControllerAnimated:NO];
//here you pop **self** from navigation controller. And now
[self navigationController] == nil;
// And
[nil viewControllers] == nil
Try to do this:
UINavigationController *nc = [self navigationController];
NSLog(@"%@", [nc viewControllers]);
[nc popViewControllerAnimated:NO];
NSLog(@"%@", [nc viewControllers]);
Upvotes: 1
Reputation:
I fixed it. The code that was popping the view was getting called in viewDidLoad. This meant it was getting popped before the view had actually animated in completely.
I moved that code to viewDidAppear and now it works as advertised.
Upvotes: 1