Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
718 views
in Technique[技术] by (71.8m points)

iphone - Problem pushing multiple view controllers onto navigation controller stack

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...