通过 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写一个类别:
iOS 开发中,可以通过实现 UINavigationControllerDelegate 协议中的 navigationController:didShowViewController:animated: 方法来拦截侧滑返回手势。 例如,你可以在这个方法中判断当前展示的视图控制器是否需要禁用侧滑返回手势,如果需要,则设置导航控制器的 interactivePopGestureRecognizer.enabled 属性为 NO,否则设置为 YES。 示例代码如下: - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { BOOL shouldEnableGesture = YES; if ([viewController conformsToProtocol:@protocol(DisablePopGestureProtocol)]) { shouldEnableGesture = [viewController disablePopGesture]; navigationController.interactivePopGestureRecognizer.enabled = shouldEnableGesture; 在这段代码中,我们新增了一个协议 DisablePopGestureProtocol,用于标记那些视图控制器需要禁用侧滑返回手势。在每个视图控制器中,如果希望禁用侧滑返回手势,则只需要实现这个协议中的 disablePopGesture 方法并返回 NO 即可。 希望这些信息对你有所帮助! fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read - Homebrew 54453 [!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `cocoapods`.- Dev 15513 fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read - Homebrew 何宇航莫得感情: cd "$(brew --repo)" zsh: command not found: brew 通过 axios 方式下载文件 mavengo: 进页面就让内容准备好,点击下载的时候再触发a连接 通过 axios 方式下载文件 Summer℡;: 这反应也太迟钝了,你怎么解决的 nz-table配置nzPageIndex、nzPageSize后数据未渲染 - Angular 拂晓东升: 也遇到了同样问题,真坑啊还有这种的 error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65.- RN m0_46563799: 你们后来搞好了吗