美文网首页
iOS界面跳转--移去中间的VC(present)

iOS界面跳转--移去中间的VC(present)

作者: 陈鸿禧 | 来源:发表于2016-08-30 10:54 被阅读88次

假设NavigationController中有A一个ViewController,
在A中presentViewControllerB,B执行某业务后跳转C
要求C返回的时候直接返回A。

1.A用self.navigationController去present B

VC2 *vc = [[VC2 alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; [self.navigationController presentViewController:nav animated:YES completion:nil];

2.B跳去C

VC3 *vc = [[VC3 alloc] init]; NSMutableArray* navArray = [[NSMutableArray alloc] initWithArray:((UINavigationController *)self.presentingViewController).viewControllers]; [navArray addObject:vc]; [(UINavigationController *)self.presentingViewController setViewControllers:navArray animated:NO]; [self.navigationController dismissViewControllerAnimated:YES completion:nil];

其它无效方案(以下写法无法跳转,想想就明白了)

[self.navigationController dismissViewControllerAnimated:YES completion:^{ [(UINavigationController *) self.presentingViewController pushViewController:vc animated:NO];}];

相关文章

网友评论

      本文标题:iOS界面跳转--移去中间的VC(present)

      本文链接:https://www.haomeiwen.com/subject/znpfettx.html