NSWindowController 代码
class RXLogAnalysisMainWindowController: NSWindowController {
@IBOutlet weak var listTableView: NSTableView!
let context: RXLogAnalysisContext! = RXLogAnalysisContext()
override func windowDidLoad() {
super.windowDidLoad()
self.listTableView.delegate = self.context.listDelegate // 这里崩溃 Unexpectedly found nil while unwrapping an Optional value
}
}
跳转的代码:
let wc = RXLogAnalysisMainWindowController(windowNibName: "RXLogAnalysisMainWindowController", owner:self)
wc.showWindow(nil)
image.png
这几个控件都是为nil
当把跳转的代码换成:
let wc = RXLogAnalysisMainWindowController(windowNibName: "RXLogAnalysisMainWindowController", owner:Bundle.main)
wc.showWindow(nil)
也出现同样的问题。
最后正确的是:
let wc = RXLogAnalysisMainWindowController(windowNibName: "RXLogAnalysisMainWindowController")
wc.showWindow(nil)
网友评论