从另一个视图控制器打开 window + 视图
Opening window + view from an other view controller
我有一个 ViewControllerOne。 ViewControllerOne 通过 Ctrl-Drag(在故事板中)连接到菜单按钮 mBtn(这意味着我不知道它是如何以编程方式实现的)。
单击此 mBtn,会出现一个 ViewOne(当前模态)。这个 ViewOne 绑定到 ViewControllerOne。 ViewOne 有一个按钮 btnOne。
单击 btnOne 我希望关闭 ViewOne 并显示 ViewTwo。 ViewTwo 属于 ViewControllerTwo 和 WindowControllerTwo。
WindowControllerTwo-ViewControllerTwo 绑定是在新项目上创建的标准案例。
我在 ViewControllerOne 中按钮 btnOne 的 IBAction 中有以下代码:
@IBAction func onbtnOnePressed(sender: AnyObject){
let m_WindowControllerTwo = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil).instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("WindowControllerTwo")) as! NSWindowController // I have no custom class for the window controller as I don't really know what I can use it for ...
let m_ViewTwo = WindowControllerTwo.contentViewController as! ViewControllerTwo // my custom class for ViewTwo
m_ViewTwo.attributeIWantToPassToThisView = self.x // an attribute I want to pass from view a to view b
m_WindowControllerTwo.contentViewController = m_ViewTwo // passing the attribute from a to b
m_WindowControllerTwo.showWindow(self) // this does not work
self.dismiss(nil) // see NOTE
}
这段代码实际上不起作用。在逐步调试时,我看到 window/view 闪烁但没有出现...
注意:我可以将按钮 btnOne 与 ctrl-drag 连接到 ViewControllerTwo。这行得通。但是现在的 ViewOne 并没有被解雇!
问题:我在这里做错了什么?在 iOS swift 这也有效。我不太明白 WindowController 的东西,所以我需要你的建议。
而不是这个:m_WindowControllerTwo.showWindow(self)
使用:
let application = NSApplication.shared()
application.runModal(for: wordCountWindow) //this will present WindowControllerTwo modally.
然后关闭您当前的控制器添加此行:PresentWindowControllerName.close()
我有一个 ViewControllerOne。 ViewControllerOne 通过 Ctrl-Drag(在故事板中)连接到菜单按钮 mBtn(这意味着我不知道它是如何以编程方式实现的)。
单击此 mBtn,会出现一个 ViewOne(当前模态)。这个 ViewOne 绑定到 ViewControllerOne。 ViewOne 有一个按钮 btnOne。
单击 btnOne 我希望关闭 ViewOne 并显示 ViewTwo。 ViewTwo 属于 ViewControllerTwo 和 WindowControllerTwo。
WindowControllerTwo-ViewControllerTwo 绑定是在新项目上创建的标准案例。
我在 ViewControllerOne 中按钮 btnOne 的 IBAction 中有以下代码:
@IBAction func onbtnOnePressed(sender: AnyObject){
let m_WindowControllerTwo = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil).instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("WindowControllerTwo")) as! NSWindowController // I have no custom class for the window controller as I don't really know what I can use it for ...
let m_ViewTwo = WindowControllerTwo.contentViewController as! ViewControllerTwo // my custom class for ViewTwo
m_ViewTwo.attributeIWantToPassToThisView = self.x // an attribute I want to pass from view a to view b
m_WindowControllerTwo.contentViewController = m_ViewTwo // passing the attribute from a to b
m_WindowControllerTwo.showWindow(self) // this does not work
self.dismiss(nil) // see NOTE
}
这段代码实际上不起作用。在逐步调试时,我看到 window/view 闪烁但没有出现...
注意:我可以将按钮 btnOne 与 ctrl-drag 连接到 ViewControllerTwo。这行得通。但是现在的 ViewOne 并没有被解雇!
问题:我在这里做错了什么?在 iOS swift 这也有效。我不太明白 WindowController 的东西,所以我需要你的建议。
而不是这个:m_WindowControllerTwo.showWindow(self)
使用:
let application = NSApplication.shared()
application.runModal(for: wordCountWindow) //this will present WindowControllerTwo modally.
然后关闭您当前的控制器添加此行:PresentWindowControllerName.close()