我有一个故事板,我有一个窗口控制器和一个视图控制器。在代码中访问视图控制器的最合理方法是通过拥有窗口控制器中定义的访问器。
class TutorialHUDWindowController: NSWindowController {
var tutorialHUDViewController: TutorialHUDViewController {
get {
return self.contentViewController! as! TutorialHUDViewController
}
}
}
所有内容编译都很好,但在运行时尝试访问视图控制器时,应用程序崩溃了一个sigabrt:
,控制台会记录与以下内容类似的错误消息:
MyApp[6178:329283] Unknown class TutorialHUDViewController in Interface Builder file at path MyApp/Build/Products/debug/Myapp/Contents/Resources/TutorialHUDStoryboard.storyboardc/NSWindowController-scR-w0-00.nib. MyApp[6178:329283] Failed to connect (otherView) outlet from (NSViewController) to (otherView): missing setter or instance variable Could not cast value of type 'NSViewController' (0x7fff89ae9410) to 'MyApp.TutorialHUDViewController' (0x1001f6a38). Myapp[6178:329283] Could not cast value of type 'NSViewController' (0x7fff89ae9410) to 'Thimble.TutorialHUDViewController' (0x1001f6a38).
我在我的应用程序的其他地方使用了类似的投射模式,并且工作正常,出了什么问题?