Swift从Segue-macOS解雇ViewController

Swift从Segue-macOS解雇ViewController,swift,macos,segue,Swift,Macos,Segue,我有一个通过脚本序列以编程方式显示的辅助ViewController: func actioncall () { performSegue(withIdentifier: "showIgnoreVC", sender: self) } ) 此函数是主ViewController的一部分,通过来自AppDelegate的NSNotification调用,而AppDelegate又由菜单项单击触发 但是,即使segue连接到主ViewController,以下代码也不会关闭次视图: @I

我有一个通过脚本序列以编程方式显示的辅助ViewController:

func actioncall ()
{
    performSegue(withIdentifier: "showIgnoreVC", sender: self)

}
)

此函数是主ViewController的一部分,通过来自AppDelegate的NSNotification调用,而AppDelegate又由菜单项单击触发

但是,即使segue连接到主ViewController,以下代码也不会关闭次视图:

@IBAction func dismiss(_ sender: Any)
{
    print("Hello?  Gonna close?")

    self.presenting?.dismissViewController(self)
}
没有错误,单击正确的解除按钮将调用该函数,但次视图不会解除。我试过了dismissViewController的各种变体,但都没有用

当我使用主视图上的一个按钮来激活同一个序列时,一切都正常工作。我只是不想用一堆按钮把主视图弄得乱七八糟


非常感谢您的任何想法。

dismissViewController仅适用于以模态方式呈现的视图控制器(使用
Present modally Segue
) 正如在对的回答中所述,您应该关闭由
Show Segue
显示的视图控制器,如下所示:

navigationController?.popViewController(animated: true)
dismiss(animated: true, completion: nil)

当这行执行时,
self.presenting?.dismissViewController(self)
,self.presenting的值是多少?@davewston,好问题。使用
让x=自我呈现!作为NSViewController
,应用程序崩溃并出现致命错误:在展开可选值时意外发现nil。显然没有viewController显示。dismissViewController适用于显示为图纸的视图控制器,也适用于显示。在此项目中,没有navigationController。谢谢你的意见。