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