View 如何在swift3中切换时间时关闭当前视图控制器

View 如何在swift3中切换时间时关闭当前视图控制器,view,swift3,segue,identifier,dismiss,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.destinatio

这是我的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,并需要打开ParentViewController(不打开,因为它仅处于打开状态)

确切地说,每当我单击SubViewController中的按钮时,SubViewController只需要关闭,然后我想ParentViewController就会自动可见(因为已经打开了一个,但我没有关闭对吗?)

如何实现这样的机制?在SubViewController按钮操作中,我编写了以下内容:

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

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

如果您在stoyboard上创建segue时选择了show。在您的按钮中调用此选项,单击:

self.navigationController?.popViewController(animated: true)
如果您选择了“以模态方式呈现”,请调用此选项:

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

这是什么样的赛格?模式或推送一个?执行模式(标识符为:“subViewController”,发送方:currentMarks),然后覆盖func prepare(对于segue:UIStoryboardSegue,发送方:Any?{如果segue.identifier==“subViewController”{//Before出现在屏幕中。让subViewController=segue.destination为!subViewController subViewController.currentMarks=sender为?Int16}不,我不是在说这个,在故事板中选择你的segue,然后检查它是模态还是推式?检查self.navigationController是否为零?同时尝试使用self.discouse(动画:,完成)抱歉,兄弟,我没有让你成为ios的新手,我创建了这样的参考,让subViewController=segue.destination as!subViewController