我有一个这样的连接:
在底部的viewController中,我尝试使用NSViewController
关闭它,但是,它会产生以下错误:
[General] dismissViewController:: Error: maybe this view controller was not presented?
我怎样才能关闭这个viewcontroller?
感谢您的帮助。
最佳答案
下面是我所做的:
在显示的窗口(NSViewController)中添加以下内容:
将此项作为属性添加到所呈现类的顶部:
class FooViewController: NSViewController {
// reference to a window
var window: NSWindow?
...
}
添加viewDidAppear的重写,而不是viewDidLoad,因为窗口句柄为nil。
override func viewDidAppear() {
// After a window is displayed, get the handle to the new window.
window = self.view.window!
}
现在,您可以在当前具有“dismissViewController”的位置使用:
窗户?.performClose(nil)//nil,因为我不返回消息
关于swift - 关闭/关闭NSViewController,macOS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53026561/