查看文件所有者无法使用的插座

发布于 2024-10-20 21:52:44 字数 357 浏览 5 评论 0原文

创建新的视图控制器时我收到以下消息。一切都在 Xcode 中编译正常,没有错误,但应用程序在从 RootViewController 加载新视图后立即退出。

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "HomeView" nib but the view outlet was not set.'

为了解决此问题,我尝试将文件所有者连接到视图,但文件所有者甚至无法使用视图出口。

I was getting the following message upon creating a new view controller. Everything was compiling a-okay in Xcode without errors, but the app was immediately quitting upon loading the new view from a RootViewController.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "HomeView" nib but the view outlet was not set.'

To resolve this, I tried connecting the File's Owner to the view, but the view outlet wasn't even available to the File's owner.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

西瓜 2024-10-27 21:52:44

根据 @Tim Post 的建议,从问题部分移出。

发现:

我终于意识到,当我添加此 View XIB 时,文件的所有者已设置为 NSObject 而不是 HomeViewController (我新创建的视图控制器)。一旦我在身份检查器中设置了类身份,视图出口就可以连接到视图了。

应用程序现在加载,并且新视图加载完美。只是为了 SO 社区的利益而分享。

结论:

创建新的视图 XIB 时,请确保在身份检查器 (Cmd+4) 中将类身份设置为所需的视图控制器。默认情况下它可以设置为 NSObject。

然后视图出口应该可用。

Moved from question section, per @Tim Post's suggestion.

Discovery:

I finally realized that when I added this View XIB, the File's Owner had been set to NSObject instead of HomeViewController (my newly-created view controller). Once I set the class identity in the indentity inspector, the view outlet was then ready to be connected to the view.

The app now loads and the new view loads perfectly. Just sharing for the benefit of the SO community.

Conclusion:

When creating a new View XIB, make sure to set the class identity to the desired view controller in the indentity inspector (Cmd+4). It may be set to NSObject by default.

The view outlet should then be available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文