文件所有者无法使用查看插座 [英] View outlet not available to File's Owner

查看:24
本文介绍了文件所有者无法使用查看插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

发现:

我终于意识到,当我添加这个 View XIB 时,File's Owner 已经设置为 NSObject 而不是 HomeViewController(我新创建的视图控制器).一旦我在身份检查器中设置了类标识,视图插座就可以连接到视图了.

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.

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

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

结论:

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

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.

这篇关于文件所有者无法使用查看插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆