当单击该窗口的相应按钮(关于NSWindow -> aboutWindow,preferences -> preferencesWindow)时,我试图让该窗口的按钮出现。但是,当我单击按钮打开窗口时,它们就会闪现,然后消失。我看到了一两篇关于这个问题的文章,描述了如何修复它,但是它比较模糊,并且在Objective中解释了,而不是Swift。我想我知道问题出在哪里(在@IBAction中创建的实例,一旦操作完成,就会清除实例),但我不知道如何修复它。
所有代码都在https://github.com/madebybright/Nimble/tree/windows结束
如果能给出解决办法的解释,我将不胜感激。
发布于 2015-09-08 23:11:47
您只需要将控制器的声明移出您的方法。就像这样:
let aboutController = AboutController(windowNibName: "About")
let preferencesController = PreferencesController(windowNibName: "Preferences")
func showAbout(sender: AnyObject) {
println("showing about window")
aboutController.showWindow(aboutController.aboutWindow)
}
func showPreferences(sender: AnyObject) {
println("showing preferences window")
preferencesController.showWindow(preferencesController.preferencesWindow)
}https://stackoverflow.com/questions/32467147
复制相似问题