如何使用导航控制器解雇两个ViewController?

时间:2019-03-13 19:46:56

标签: ios swift segue uistoryboardsegue dismissviewcontroller

我有三个相关的视图,它们都通过推式Segues连接到导航控制器(另外,我还使用prepare for segue来存储所有三个数组)。所以我想使用dismiss,因为我不想更改视图控制器中已经使用的存储数组。

所以我在viewcontroller C上,我试图回到A。

到目前为止,我一直使用self.dismiss(animated: true, completion: nil),在关闭视图B时效果很好,但是我想转到视图A。

我也尝试使用:

let presentingViewController = self.presentingViewController
presentingViewController?.presentingViewController?.presentingViewController?.dismiss(animated: false, completion: nil)

但是这不起作用,并产生此错误:

  

pushViewController:animated:在发生现有转换或演示时调用;导航堆栈将不会更新。

有什么解决办法吗?

我想去Viewcontroller A的原因是因为在Viewcontroller C上进行了某些更新时Viewcontroller B中存在一个错误,因此一个临时解决方案是直接转到A并重新加载tableview。

1 个答案:

答案 0 :(得分:0)

在导航控制器上调用setViewControllers(_:animated:),传入仅包含视图控制器A的数组。由于视图控制器A已在堆栈中,因此动画将是弹出窗口。

或者,如果您想使用segue,则可以perform an unwind segue,返回到控制器A。

相关问题