我有6个UIViewControllers与推送segue连接,带有标识符和我的应用程序中的功能,使用此方法“跳转”到所需的UIViewController
以堆叠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
六个将会显示动画。
但是在iOS8上会出现奇怪的行为。系统会在短时间内向我显示UIViewcontroller
5,然后转到UIViewcontroller
6.这是我不想要的。
总结一下:
iOS 7:1 -----> 6 - 理想的
iOS 8:1 -----> 5(短暂的一段时间)----> 6 - 不受欢迎
我的问题是如何使用iOS 8实现理想效果.Ty!
答案 0 :(得分:3)
使用方法:
- (void)setViewControllers:(NSArray *)viewControllers
animated:(BOOL)animated
一次设置所有控制器只显示最后一个。
在你的情况下:
- (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];
}