gpt4 book ai didi

xcode - 为什么我无法在 Storyboard中转换到我的 View Controller 子类?

转载 作者:行者123 更新时间:2023-12-03 17:09:31 27 4
gpt4 key购买 nike

我有一个 Storyboard,其中有一个窗口 Controller 和一个 View Controller 。在代码中访问 View Controller 的最合理方法是通过所属窗口 Controller 中定义的访问器。

class TutorialHUDWindowController: NSWindowController {

var tutorialHUDViewController: TutorialHUDViewController {
get {
return self.contentViewController! as! TutorialHUDViewController
}
}

}

一切都编译得很好,但是当尝试在运行时访问 View Controller 时,应用程序崩溃并出现 sigabrt:

enter image description here

并且控制台记录类似于以下的错误消息:

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 variableCould 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).

我在应用程序的其他地方使用了类似的转换模式,并且一切正常,出了什么问题?

最佳答案

在 Storyboard中,自定义类 View Controller 引用还应该引用它所在的相应模块。如果是“MyApp”,则将其设置为“MyApp”,或者使用“从目标继承”选项。

enter image description here

此外,您可能需要在再次构建之前进行“清理”,以清除任何缓存的 Storyboard编译。

关于xcode - 为什么我无法在 Storyboard中转换到我的 View Controller 子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517141/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com