从第三个ViewController中关闭第二个ViewController

时间:2017-07-14 09:16:16

标签: ios swift viewcontroller dismiss

我正在尝试从VC c中解除VC b,其中VC c是一个弹出窗口,并且有一个用于注销的按钮,但它无法正常工作。 流程的结构是

VC a ----presents modally----> VC b ----presents a popover----> VC c

单击弹出框中的按钮时,必须关闭VC c和VC b,以便调用(VC a)ViewWillAppear。

6 个答案:

答案 0 :(得分:2)

试试这个:

您可以从子视图控制器中关闭presentingViewController,如下所示

self.presentingViewController?.dismiss(animated: true, completion: nil)

将ViewController添加为childViewController

self.parent?.dismiss(animated: true, completion: nil) 

如果此视图控制器是包含视图控制器(例如导航控制器或标签栏)的子视图       控制器)

weak open var parent: UIViewController? { get }

此视图控制器或其最近的祖先提供的视图控制器。

open var presentedViewController: UIViewController? { get }

提供此视图控制器(或其最远的祖先。)的视图控制器。

open var presentingViewController: UIViewController? { get }

答案 1 :(得分:0)

如果ViewControllers具有类似

的层次结构

VC a ----以模态方式呈现为self.present(objects, animated: true, completion: nil) ----> VC b ----表示为self.present(objects, animated: true, completion: nil) popover ----> VC c

VC c上有一个按钮可以移回VC,然后你可以使用:

self.presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil)

答案 2 :(得分:0)

首先尝试从自身中解除VC b,而不是使用:self.dismiss(animated: true, completion: nil)或者如果VC b嵌入在导航控制器中,只是为了检查VC c是否有效,如下所示:{{1 }}

如果上面的那个工作,我建议你实现委托协议,VC c将委托给VC解雇,只要它应该完成。您也可以使用完成块,其中包含self.navigationController?.dismiss(animated: true, completion: nil)代码。

答案 3 :(得分:0)

  

希望这有效

{{1}}

答案 4 :(得分:0)

`protocol ModalHandler {
    func modalDismissed()
Class SecondViewController: UIViewController, ModalHandler {
    func modalDismissed() {
        self.dismiss(animated: false, completion: nil)
   }
   func open3rdController() {
       let thirdVC = ThirdViewController(_ )
       thirdVC.delegate = self
       self.present(thirdVC, animated: true, completion: nil)
   }
class ThirdViewController: UIViewController {
    func dismiss() {
        self.delegate.modalDismissed()
   }
}
`

答案 5 :(得分:0)

关于PresenterCoordinator的情况。

此实例将初始化所有这些VC并显示它们。 您也可以从那里解散它们。

相关问题