Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
721 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...