【发布时间】:2020-06-29 15:08:42
【问题描述】:
我正在构建一个用于生产的 Cocoa 应用程序,当我为没有 NSStoryboard 实例化的路由创建 NSViewController 时,我收到了如下错误。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: ContentFully.AnotherController in bundle (null).
实际上我通过使用NSViewController 添加NSStoryboard 解决了我的问题,但我想了解当我以编程方式调用它时发生了什么以及为什么会崩溃?
工作场景
let storyboard = NSStoryboard(name: "Dashboard", bundle: nil)
let vc = storyboard.instantiateInitialController() as! AnotherController
崩溃场景
let vc = AnotherController()
self.view.window?.contentViewController = vc
即使我完全以编程方式创建一个与NSStoryboard 无关的类,当我更改contentViewController 时,我也无法使用它。是否需要在NSBundle 中的每个控制器中搜索Swift?
提前致谢
【问题讨论】: