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

假设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];}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容