如何在swift3中的segue时间内关闭当前视图控制器

时间:2017-05-10 10:03:20

标签: view swift3 segue identifier dismiss

这是我的segue方法。假设这个方法在ParentViewController中。

override fu n c prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "subViewController" {
        // Before appears in the screen.
        let subViewController = segue.destination as! SubViewController
        subViewController.currentMarks = sender as? Int16
}

工作完美。现在来到SubViewController。在这里,我正在做一些事情,我在这里有一个按钮。每当我单击此按钮时,它应该关闭SubViewController并需要打开ParentViewController(不打开,因为它只是已经打开状态)。

每当我点击SubViewController中的按钮时,subViewController只需要解除然后自动显示ParentViewController我会想到(因为已经打开了一个我只是没有关闭吗?)。

如何实现这种机制?在SubViewController按钮操作中,我写了这个:

self.navigationController?.dismiss(animated: true, completion: {
    })

但它不起作用。请有人帮帮我吗?

1 个答案:

答案 0 :(得分:4)

如果您在stoyboard上创建segue时选择显示。在按钮单击中调用此方法:

self.navigationController?.popViewController(animated: true)

如果您选择提交模态,请将其命名为:

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