- 传入要返回的控制器类
[ViewController class]
,支持返回任意指定的控制器
- (IBAction)goBack:(id)sender {
[self backAction:[ViewController class]];
}
- (void)backAction:(Class)aClass {
UINavigationController *nav = self.navigationController;
NSMutableArray *viewControllers = [NSMutableArray array];
for (UIViewController *vc in [nav viewControllers]) {
[viewControllers addObject:vc];
if ([vc isKindOfClass:aClass]) {
break;
}
}
[nav setViewControllers:viewControllers animated:YES];
}
网友评论