通过 self.navigationController 的 viewControllers 中遍历寻找所需的 class 方式;
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[YHInvoiceRecordsListVC class]]) {
[self.navigationController popToViewController:vc animated:YES];
return ;
通过 self.navigationController 的 viewControllers 数组中的 index 方式,更加类似于前端的模式;
该方式需要预先确定清业务逻辑且中间 push 视图的流程一致性,若中间页面视图可能会有分支出现的情况,不建议使用该方式;
NSInteger index=[[self.navigationController viewControllers] indexOfObject:self];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:index - 2] animated:YES];
以上便是此次分享的全部内容,希望能对大家有所帮助!
日常开发中经常会遇到页面不按层级压栈的方式每个层级依次返回的情况;如下有两种方式可以满足跳栈的情况,从当前视图返回至之前的某个层级;方式一通过 self.navigationController 的 viewControllers 中遍历寻找所需的 class 方式;for (UIViewController *vc in self.navigationController.viewControllers) { if ([vc isKindOfClass:[YHInvoiceR.
[self.navigationController popViewControllerAnimated:YES];
UINavigationController返回总结:
1、弹出当前视图控制器(弹出并向左显示前一个视图)
[self.navigationController popToViewController:viewController animated:YES];
我上传app两次都被拒,最后发现我修改后的代码需要也把获取
navigationcontroller栈中的最后一个
视图控制器修改为获取
navigationcontroller栈中的倒数第二个
视图控制器,查了下资料在点击打开链接找到了解决方案:
原理就是把
navigationController栈中的
视图控制器存到一个数组里,然后从这个数组里就可以任意获取自己想要的
视图控制器了。
如果你在NavigationController中只需要向上返回一层view,可以用下面这句代码
[self.navigationController popViewControllerAnimated:YES];
有时候我们的NavigationController下面会有好几层,进到里面的view之后又想返回到上面的几层view,只要是同一个NavigationController父类下的vi
在
ios开发的过程中,我们经常需要修改
NavigationController的背景颜色,当使用方法[self.
navigationController.
navigationBar setBackgroundColor:[UIColor redColor]]时,运行的结果并不能修改北京颜色:
现在提供一种新方法来解决这个问题:
写一个
NavigationBar写一个类别: