方法一:
UINavigationControllerDelegate
这个代理真的很简单,就是当一个viewController要显示的时候通知一下外面,给你一个机会进行设置,包含如下两个函数:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
当你需要对某些将要显示的viewController进行修改的话,可实现该代理。
在B界面实现代码:
方法二:
这是在C页面中的代码:
- (void)viewDidLoad {
[superviewDidLoad];
//得到当前视图控制器中的所有控制器
NSMutableArray*array = [self.navigationController.viewControllers mutableCopy];
//把B从里面删除
[array removeObjectAtIndex:1];
//把删除后的控制器数组再次赋值
[self.navigationController setViewControllers:[array copy] animated:YES];
}
方法三
UIViewController*viewController=nil;
for(UIViewController*tempVc in self.navigationController.viewControllers) {
if([tempVc isKindOfClass:[RFSelectHeadTypeViewController class]]) {
viewController=tempVc;
}
}
[self.navigationController popToViewController:viewController animated:YES];
利用模态跳转,从A present到B,再从B present到C,然后从C present到D,最后要从D返回到A,返回过程如下:
-(void)dismissModalStack {
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:NULL];
}
网友评论