如何将视图控制器弹出到swift中以前的一个视图控制器? [英] How to pop view controller to one of the previous view controllers in swift?

查看:71
本文介绍了如何将视图控制器弹出到swift中以前的一个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将视图控制器弹出到视图堆栈中以前的视图控制器之一。假设我的视图堆栈中有 firstVC,secondVC,thirdVC和4thVC 视图控制器。当前视图控制器是第四个,并且在第四个VC中有一个tableview。如果用户删除tableview中的所有行,我应该将用户定向到 secondVC 。我有一个想法,我将创建另一个navigationcontroller并使用 presentViewController 命令显示它。但是,这不是我的问题的解决方案。因为我认为这种情况会出现导航问题。我怎样才能找到这种情况的最佳解决方案?

I have been trying to pop my view controller to one of previous view controllers in my view stack. Assume that, There are firstVC, secondVC, thirdVC and fourthVC viewcontrollers in my view stack. The current view controller is fourth one, and there is a tableview in fourthVC. If user delete all the rows in tableview, I should direct the user to secondVC. I had an idea that I would create another navigationcontroller and present it with presentViewController command. However, this is not a solution for my problem. Because I thougt that a navigation problem appears for this case. How can I find best solution for this case ?

感谢您的回答,
祝您好运

Thank you for your answers, Best regards

推荐答案

而不是做一般的 popViewControllerAnimated:调用,使用 popToViewController:animated:。您可以检测用户是否已删除所有行,在这种情况下执行此类操作(否则只需弹出一个视图控制器):

Instead of doing a generic popViewControllerAnimated: call, use popToViewController:animated:. You could detect if the user has deleted all of the rows in which case, do something like this (otherwise just pop one view controller):

let viewControllers: [UIViewController] = self.navigationController!.viewControllers as [UIViewController];
self.navigationController!.popToViewController(viewControllers[viewControllers.count - 2], animated: true);

这篇关于如何将视图控制器弹出到swift中以前的一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆