我试图让 NSWindow 在单击该窗口的相应按钮时出现(about -> aboutWindow、preferences ->preferencesWindow)。但是,当我单击按钮打开窗口时,它们会闪烁,然后消失。我看到一两篇关于这个问题的文章描述了如何修复它,但它相对模糊,并且是用 Objective-C 解释的,而不是 Swift。我想我知道问题是什么(在 @IBAction
内创建实例,操作完成后删除该实例),但我不确定如何修复它。
所有代码均已结束于https://github.com/madebybright/Nimble/tree/windows
对修复的解释将非常感激。
最佳答案
您只需将 Controller 的声明移出方法即可。尝试这样:
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)
}
关于macos - NS窗口闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32467147/