一、如何判断是从哪个控制器push进来的
遵循代理方法:<UINavigationControllerDelegate>
实现代理方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// 判断类型
if (viewController isKindOfClass:[MyViewController Class]){
// Todo Code
}
}
当然还有更多的方法判断
例如获取最后一个控制器:
self.navigationController.viewControllers.lastObject
二、返回指定控制器
1、返回到上一个控制器视图
[self.navigationController popoverPresentationController];
2、返回到上上个控制器视图
NSArray * viewControllers = self.navigationController.viewControllers;
UIViewController * viewController = [viewControllers objectAtIndex:viewControllers.count - 1];
3、返回到指定控制器
NSArray * viewControllers = self.navigationController.viewControllers;
for (UIViewController * item in viewControllers) {
if (item isKindOfClass:[MyViewController Class]) {
[self.navigationController popToViewController:item animated:YES];
return
}
}
网友评论