Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem pushing multiple view controllers onto navigation controller stack

Tags:

iphone

I am trying to push three view controllers onto the navigation controller.

  [self.navigationController pushViewController:one animated:YES];
  [self.navigationController pushViewController:two animated:YES];
  [self.navigationController pushViewController:three animated:YES];

The desired behavior is that view three will show, and when the back button is pressed it will go to view two and then to view one...

What actually happens is that view one is visible and pressing back goes to view two and then back again it goes to view one. Which is to say that view one is shown instead of view three.

Very strangely, looking at the viewController array of the navigationController after the calls above show the right entries, and looking at the visibleViewController property shows that it has view three in it... even though view one is visible.

If I navigate to a sub view from the visible view one (that shows in the place of view three) and press back from that sub view... it goes to view three.

It looks like it is showing view one, but knows it is on view three...

I am completely confused... any ideas?

Jim

like image 965
Jim Avatar asked Apr 11 '10 23:04

Jim


1 Answers

For the first two pushes, don't pass the animated flag in as YES, set it to NO:

[self.navigationController pushViewController:one animated: NO]; 
[self.navigationController pushViewController:two animated: NO];
[self.navigationController pushViewController:three animated: YES];

This will give you the effect you want. Otherwise, you're confusing the animation system, as it tries to animate three views into the same space.

like image 130
Ben Gottlieb Avatar answered Dec 22 '22 22:12

Ben Gottlieb