ViewController的出口视图首先为非零,然后从捆绑包加载时为零 [英] ViewController's outlet view first non-nil, then nil when loading from bundle

查看:61
本文介绍了ViewController的出口视图首先为非零,然后从捆绑包加载时为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从具有 initWithNibName:bundle:的捆绑包中加载 UIViewController 。如果我在其 viewDidLoad 中设置一个断点,则可以看到其 view 已设置。当在Interface Builder中查看 About.xib 时,我也可以看到这一点。

I am loading a UIViewController from a bundle with initWithNibName:bundle:. If I set a breakpoint in its viewDidLoad I can see that its view is set. I can also see this when viewing About.xib in the Interface Builder.

但是实际上是第一次使用视图时(在对 [self.navigationController pushViewController:viewController animation:YES]的调用中根据我的应用程序的逻辑)我收到此错误:

However once the view is actually used for the first time (in a call to [self.navigationController pushViewController:viewController animated:YES] according to my app's logic) I get this error:


* 由于以下原因终止了应用程序:未捕获的异常'NSInternalInconsistencyException',原因:'-[UIViewController
_loadViewFromNibNamed:bundle:]加载了关于笔尖,但未设置视图出口。'

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

此调用也会触发 viewDidLoad 。因此,显然在通话期间,视图首先是非零的(应该是),后来显然又变为零。

This is the call that also triggers viewDidLoad. So apparently during the call, view is first non-nil (as it should be) and later apparently becomes nil again.

如果我在调用之前紧接着在调试器中键入 po [viewController view] ,则会收到此错误(可能只是出现相同症状的另一种表示形式):

If I alternatively type po [viewController view] in the debugger immediately prior to the call I get this error (which is presumably just another presentation of the same symptom):


错误:执行被中断,原因:内部ObjC异常
断点(-3)。该过程已返回到
表达式评估之前的状态。

error: Execution was interrupted, reason: internal ObjC exception breakpoint(-3).. The process has been returned to the state before expression evaluation.

如何在不使用现有导航栏的情况下加载和使用视图控制器遇到这些错误?

How can I load and use the view controller in conjunction with an existing navigation bar without running into these errors?

更新如果我从故事板(不一定是我的主故事板)加载视图控制器,问题显然消失了

UPDATE The problem apparently disappears if I load the view controller from my a storyboard (not necessarily my main storyboard) instead of from a XIB file.

推荐答案

我的猜测是您正在覆盖某些默认的 UI ViewController 行为,或者将其 view 设置为属性,这是一个奇怪的 loadView 方法,或者只是不使用您覆盖的方法之一调用 super

My guess is that you were overriding some default UIViewController behavior, either make its view a weak property, a strange loadView method or just not calling super in one of your overridden methods.

另一个常见错误是调用不匹配的 super 方法(调用 super viewDidLoad 来自 awakeFromNib 等),这可能是在您四处移动代码或尝试其他操作后发生的。

Another common error is calling a non-matching super method (call super viewDidLoad from an awakeFromNib, etc.) which could happen when you move code around or after trying different things.

这篇关于ViewController的出口视图首先为非零,然后从捆绑包加载时为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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