联系人:石虎 QQ:1224614774 昵称: 嗡嘛呢叭咪哄
QQ群:807236138群称:iOS 技术交流学习群
一、概念
方式一 :根据指定的类名返回
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[要返回的类名 class]]) {
[self.navigationController popToViewController:controller animated:YES];
}
}
---------------------------我是分割线-------------------------------
方式二:根据栈的索引返回
NSArray *temArray = self.navigationController.viewControllers;
[self.navigationController popToViewController:[temArray objectAtIndex:1] animated:YES];
打印:
Printing description of temArray:
<__NSArrayI 0x1054a20c0>(
)
---------------------------我是分割线-------------------------------
方式三:类似方式一,推荐使用方式一
NSArray *temArray = self.navigationController.viewControllers;
SHSpecialHistoryViewController *test = [[SHSpecialHistoryViewController alloc] init];
for(UIViewController *temVC in temArray){
if([temVC isKindOfClass:[test class]]) {
[self.navigationController popToViewController:temVC animated:YES];
}
}
---------------------------我是分割线-------------------------------
方式四:
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if (appDelegate.window.rootViewController) appDelegate.window.rootViewController = nil;
SHSpecialHistoryViewController *specialHistoryVC = [[SHSpecialHistoryViewController alloc]init];
appDelegate.window.rootViewController = [[SHNavigationController alloc] initWithRootViewController:specialHistoryVC];
---------------------------我是分割线-------------------------------
方式五:
SHSpecialHistoryViewController *test = [[SHSpecialHistoryViewController alloc] init];
[self.navigationController pushViewController:specialHistoryVC animated:YES];
---------------------------我是分割线-------------------------------
方式六:
dissmiss 返回根部控制器
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:NO completion:nil];