我正在编写一个基于NSDocument的应用程序。目前,我多次致电AppKit > NSDocument > func addWindowController(_ windowController: NSWindowController)
,以每个NSDocument打开多个窗口。
override func makeWindowControllers() {
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil)
let sceneidentifier : [String] = [ "si1", "si2" ]
for x in 0..<sceneidentifier.count {
let wc = storyboard.instantiateController(withIdentifier: NSStoryboard.sceneidentifier("WindowController")) as! NSWindowController
wc.contentViewController = storyboard.instantiateController(withIdentifier: NSStoryboard.sceneidentifier(sceneidentifier[x])) as? NSViewController
self.addWindowController(wc)
}
}
作为此代码的结果,每个NSDocument应该显示多个窗口,但有时在运行时随机地只出现一个窗口。