【发布时间】:2018-08-13 02:53:30
【问题描述】:
我有一个 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
}
此代码实际上不起作用。在逐步调试它时,我看到窗口/视图闪烁但没有出现......
注意:我可以通过 ctrl-drag 将按钮 btnOne 连接到 ViewControllerTwo。这行得通。但是当前的 ViewOne 并没有被解雇!
问题:我在这里做错了什么?在 iOS swift 中,这也有效。我不太了解 WindowController 的东西,所以我需要你的建议。
【问题讨论】:
-
由于您提到的命名,您的问题非常令人困惑。而不是这样做使用 viewControllers 本身的名称。
-
改了……我猜现在更清楚了
标签: swift macos view window viewcontroller