views:

1184

answers:

3

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:

  • Tab View template
    • Navigation controller
      • View controller (Loaded from the xib)
      • View controller (Pushed, what I want to pop)

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?

A: 

[[self navigationController] popViewControllerAnimated:NO];
//here you pop self from navigation controller. And now [self navigationController] == nil;
And [nil viewControllers] == nil of cource

Try to do this:

UINavigationController *nc = [self navigationController];
NSLog(@"%@", [nc viewControllers]);
[nc popViewControllerAnimated:NO];
NSLog(@"%@", [nc viewControllers]);
oxigen
Ok, this shows that it is *not* emptying the whole stack. BUT it still does not have the desired effect. The UITableView remains while the navigation controls disappear (leaving the background gradient however, the "bar")...
Paxton
A: 

What's 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.

Jordan
A: 

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.

Paxton