iOS8 issue when trying to push multiple UIViewControllers in NavigationController

血红的双手。 提交于 2019-12-23 02:21:32

问题


I have 6 UIViewControllers connected with push segues with identifiers and a functionality in my app to 'jump' to the desired UIViewController using this method for stacking ViewControllers:

- (void) JumpTo6 {
UINavigationController *nav = self.navigationController;
UIViewController *a =[self.storyboard instantiateViewControllerWithIdentifier:@"2"];
[nav pushViewController:a animated:NO];
UIViewController *b =[self.storyboard instantiateViewControllerWithIdentifier:@"3"];
[nav pushViewController:b animated:NO];
UIViewController *c =[self.storyboard instantiateViewControllerWithIdentifier:@"4"];
[nav pushViewController:c animated:NO];
UIViewController *d =[self.storyboard instantiateViewControllerWithIdentifier:@"5"];
[nav pushViewController:d animated:NO];
UIViewController *e =[self.storyboard instantiateViewControllerWithIdentifier:@"6"];
[nav pushViewController:e animated:YES];

When using iOS7 everything worked fine. I would fire this method, and let's say I was on UIViewController one, the system would stack every UIViewController up to UI VC 6 and UIViewController six would get presented with the animation.

But on iOS8 strange behaviour appears. The system shows me the UIViewcontroller 5 for a brief period of time, and then goes to UIViewcontroller 6. This is something I don't want.

To sum things up:

iOS 7: 1 -----> 6 - desirable

iOS 8: 1 -----> 5 (for a brief period of time) ----> 6 - undesirable

My question is how to achieve desirable effect using iOS 8. Ty!


回答1:


Use the method:

- (void)setViewControllers:(NSArray *)viewControllers
              animated:(BOOL)animated

to set all the controllers at a time showing only the last.

In your case:

- (void) JumpTo6 {
  UINavigationController *nav = self.navigationController;
  UIViewController *a = [self.storyboard instantiateViewControllerWithIdentifier:@"2"];
  UIViewController *b = [self.storyboard instantiateViewControllerWithIdentifier:@"3"];
  UIViewController *c = [self.storyboard instantiateViewControllerWithIdentifier:@"4"];
  UIViewController *d = [self.storyboard instantiateViewControllerWithIdentifier:@"5"];
  UIViewController *e = [self.storyboard instantiateViewControllerWithIdentifier:@"6"];
  NSArray *viewControllers = nav.viewControllers;
  NSArray *newViewControllers = [NSArray arrayWithObjects:a, b, c, d, e, nil];
  [nav setViewControllers:[viewControllers arrayByAddingObjectsFromArray:newViewControllers] animated:YES];
}


来源:https://stackoverflow.com/questions/26169483/ios8-issue-when-trying-to-push-multiple-uiviewcontrollers-in-navigationcontrolle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!