尝试在NavigationController中推送多个UIViewControllers时出现iOS8问题 [英] iOS8 issue when trying to push multiple UIViewControllers in NavigationController

查看:90
本文介绍了尝试在NavigationController中推送多个UIViewControllers时出现iOS8问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有6个UIViewControllers与push segues连接,在我的应用程序中使用标识符和功能跳转到所需的 UIViewController ,使用此方法堆叠ViewControllers:

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];

使用iOS7时一切正常。我会解雇这个方法,让我说我在 UIViewController 一,系统会将每个 UIViewController 堆叠到UI VC 6和 UIViewController 六个将显示动画。

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.

但是在iOS8上会出现奇怪的行为。系统在短时间内向我显示 UIViewcontroller 5,然后转到 UIViewcontroller 6.这是我不想要。

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.

总结一下:

iOS 7:1 ----- > 6 - 可取

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

iOS 8:1 -----> 5(短暂的一段时间)----> 6 - 不受欢迎

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

我的问题是如何使用iOS 8实现理想效果.Ty!

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

推荐答案

使用方法:

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

将所有控制器设置为仅显示最后一个控制器。

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

在你的情况下:

- (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];
}

这篇关于尝试在NavigationController中推送多个UIViewControllers时出现iOS8问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆