美文网首页
UINavigationController跳转和返回到任意一级

UINavigationController跳转和返回到任意一级

作者: 韩七夏 | 来源:发表于2016-04-06 00:05 被阅读1438次

关于ios中 viewcontroller的跳转问题,其中有一种方式是采用navigationController pushViewController 的方法,比如我从主页面跳转到了一级页面,又从一级页面跳转到了二级页面,然后从二级页面跳转到了三级页面,依次类推。,如果一级一级的返回我知道是没有问题的,调用navigationControllerpopViewControllerAnimated就行了。。但是某些情况下我可能想要马上回到主页面,而不是一级一级的返回(如果有很多层会很累的),那该怎么办呢?

返回根页面vc用 :

[self.navigationController popToRootViewController];

返回指定的某个vc用下面(通过index定位)

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];

或(通过class定位)

for(UIViewController *controller in self.navigationController.viewControllers) {

if([controller isKindOfClass:[你要跳转到的Controllerclass]]) {

[self.navigationController popToViewController:controller animated:YES];

}

}

相关文章

网友评论

      本文标题:UINavigationController跳转和返回到任意一级

      本文链接:https://www.haomeiwen.com/subject/lpoplttx.html