iPhone - 为什么我在视图映射正确时收到此错误?

时间:2022-03-24 22:50:32

My iPhone app was running fine. I added a component to my xib file (an activity indicator). I have created my own init method and am using the XIB name in the init method. Now I get this error when I do a pushViewController

我的iPhone应用运行正常。我在我的xib文件中添加了一个组件(一个活动指示器)。我已经创建了自己的init方法,并在init方法中使用了XIB名称。现在我在执行pushViewController时遇到此错误

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

I know this usually crops up when the viewcontroller is not mapped to the view in the xib. But all mappings are fine. I even deleted the class and xib and created them again. The init method is also not returning a nil. But I still get the exception as soon as I call a pushViewController with the object of this class.

我知道,当viewcontroller未映射到xib中的视图时,通常会出现这种情况。但所有映射都很好。我甚至删除了类和xib并再次创建它们。 init方法也没有返回nil。但是当我用这个类的对象调用pushViewController时,我仍然会得到异常。

Any ideas why?

有什么想法吗?

Edit

Was just debugging and called a method in the viewcontroller before calling a pushViewController on it. The debugger shows that the nib name is set properly, the bundle is nil (coz thats what am passing) but the view is also nil. No idea why!!!

在调用pushViewController之前,只是在viewcontroller中调试并调用了一个方法。调试器显示nib名称设置正确,bundle是nil(因为这是通过的)但视图也是nil。不明白为什么!!!

**Posting the code in case it helps **

**发布代码以防有害**

MyThumbnailViewController *modCont = [[[MyThumbnailViewController alloc] initWithNibName:@"MyThumbnailView" bundle:nil] autorelease];
[modCont setImgName:imgName count:numOfValues andIndex:0];

[[self navigationController] pushViewController:modCont animated:YES]; //This gives the exception

This is the viewDidLoad of the MyThumbnailViewController class. The control never reaches here

这是MyThumbnailViewController类的viewDidLoad。控制永远不会到达这里

- (void)viewDidLoad {
    self.navigationItem.title = imageName;
    self.navigationItem.hidesBackButton = NO;
    [[self navigationController] setNavigationBarHidden:NO];
}

I removed the custom init method but still getting the same error.

我删除了自定义init方法但仍然得到相同的错误。

SOLVED

Just created the whole thing again and now it works fine, though I don't see ANY differences in both the things!

刚创造了整个东西,现在它工作正常,虽然我没有看到这两件事的任何差异!

3 个解决方案

#1


I'm sure you tried this already but just in case have you set a breakpoint at the location before the method is called to handle your pushView and step through the code to see where the exception is being thrown. This sometimes helps. I'll check back later to see what you find out and to see if I can offer any more help.

我确定你已经尝试过了,但为了防止你在调用方法之前在该位置设置一个断点来处理你的pushView并逐步查看代码以查看异常被抛出的位置。这有时会有所帮助我稍后会回来看看你发现了什么,看看我是否能提供更多的帮助。

#2


Sounds strange, but just to be safe maybe double check the following again: Open IB and select File's Owner. Then in the Identity Inspector make sure the Class is set your custom View Controller. Open the Connections Inspector and make sure that the view Outlet is connected to the View in the NIB (this is what the exception is complaining about).

听起来很奇怪,但为了安全起见,请再次仔细检查以下内容:打开IB并选择文件所有者。然后在Identity Inspector中确保将Class设置为自定义View Controller。打开Connections Inspector并确保视图Outlet连接到NIB中的View(这是异常抱怨的内容)。

Save the XIB File and close IB. Then in XCode select Build->Clean All Targets and try running your app.

保存XIB文件并关闭IB。然后在XCode中选择Build-> Clean All Targets并尝试运行您的应用程序。

I have seen IB and XCode drifting apart more than once, me eagerly editing Views in IB that my App would never load because I did not add them to my project by accident. So I can feel your pain :-)

我已经看到IB和XCode不止一次分离,我急切地编辑IB中的视图,我的应用程序永远不会加载,因为我没有意外地将它们添加到我的项目中。所以我能感受到你的痛苦:-)

#3


I got this same error - after poking around I reattached the VIEW OUTLET (in File's Owner) to the VIEW in VIEW CONTROLLER (I just connected to the main part of the VIEW screen - sorry I am new to all this so I am sure I am not calling these things by the correct name) and that fixed it. It had worked before, but something I did must have broken that link.

我得到了同样的错误 - 在我四处寻找后,我将VIEW OUTLET(在文件所有者中)重新连接到VIEW CONTROLLER中的VIEW(我刚刚连接到VIEW屏幕的主要部分 - 对不起,我对这一切都是新手,所以我相信我我没有用正确的名字称呼这些东西)并修复了它。它之前曾经奏效,但我所做的事情必定打破了这个环节。

FogCityFun

#1


I'm sure you tried this already but just in case have you set a breakpoint at the location before the method is called to handle your pushView and step through the code to see where the exception is being thrown. This sometimes helps. I'll check back later to see what you find out and to see if I can offer any more help.

我确定你已经尝试过了,但为了防止你在调用方法之前在该位置设置一个断点来处理你的pushView并逐步查看代码以查看异常被抛出的位置。这有时会有所帮助我稍后会回来看看你发现了什么,看看我是否能提供更多的帮助。

#2


Sounds strange, but just to be safe maybe double check the following again: Open IB and select File's Owner. Then in the Identity Inspector make sure the Class is set your custom View Controller. Open the Connections Inspector and make sure that the view Outlet is connected to the View in the NIB (this is what the exception is complaining about).

听起来很奇怪,但为了安全起见,请再次仔细检查以下内容:打开IB并选择文件所有者。然后在Identity Inspector中确保将Class设置为自定义View Controller。打开Connections Inspector并确保视图Outlet连接到NIB中的View(这是异常抱怨的内容)。

Save the XIB File and close IB. Then in XCode select Build->Clean All Targets and try running your app.

保存XIB文件并关闭IB。然后在XCode中选择Build-> Clean All Targets并尝试运行您的应用程序。

I have seen IB and XCode drifting apart more than once, me eagerly editing Views in IB that my App would never load because I did not add them to my project by accident. So I can feel your pain :-)

我已经看到IB和XCode不止一次分离,我急切地编辑IB中的视图,我的应用程序永远不会加载,因为我没有意外地将它们添加到我的项目中。所以我能感受到你的痛苦:-)

#3


I got this same error - after poking around I reattached the VIEW OUTLET (in File's Owner) to the VIEW in VIEW CONTROLLER (I just connected to the main part of the VIEW screen - sorry I am new to all this so I am sure I am not calling these things by the correct name) and that fixed it. It had worked before, but something I did must have broken that link.

我得到了同样的错误 - 在我四处寻找后,我将VIEW OUTLET(在文件所有者中)重新连接到VIEW CONTROLLER中的VIEW(我刚刚连接到VIEW屏幕的主要部分 - 对不起,我对这一切都是新手,所以我相信我我没有用正确的名字称呼这些东西)并修复了它。它之前曾经奏效,但我所做的事情必定打破了这个环节。

FogCityFun