我有以下代码来在我的macOS应用程序中显示一个新窗口。这是在NSOpenPanel的completionHandler中。
let mainStoryBoard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil)
let windowController = mainStoryBoard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "WindowController")) as! NSWindowController
let myController = windowController.window!.contentViewController as! ViewController
myController.imageView.image = mainImage
windowController.showWindow(self)在上面定义了mainImage。
问题是这个代码在macOS高塞拉上运行得很好,但在macOS塞拉上,窗口有时会显示一瞬间,然后消失。
为什么这对macOS高塞拉有效,而对macOS塞拉无效?
发布于 2018-01-04 08:40:24
我能够通过固定windowController的作用域来解决这个问题。将变量的声明移到完成处理程序的上方,并将其设置为nil以启动,修复了该问题。
我还添加了NSWindowDelegate,并使用函数windowWillClose将windowController设置回nil,以确保它被正确发布。
发布于 2019-04-05 15:28:36
取消选中NSWindow的延迟选项。
https://stackoverflow.com/questions/48084075
复制相似问题