简体   繁体   English

iPhone-当视图映射正确时,为什么会出现此错误?

[英]iPhone - Why am I getting this error when the view mapping is correct?

My iPhone app was running fine. 我的iPhone应用程序运行良好。 I added a component to my xib file (an activity indicator). 我在xib文件中添加了一个组件(活动指示器)。 I have created my own init method and am using the XIB name in the init method. 我已经创建了自己的init方法,并且在init方法中使用了XIB名称。 Now I get this error when I do a pushViewController 现在当我执行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. 我知道,当viewcontroller未映射到xib中的视图时,通常会出现这种情况。 But all mappings are fine. 但是所有映射都可以。 I even deleted the class and xib and created them again. 我什至删除了类和xib并再次创建了它们。 The init method is also not returning a nil. init方法也不返回nil。 But I still get the exception as soon as I call a pushViewController with the object of this class. 但是,只要使用此类的对象调用pushViewController,我仍然会收到异常。

Any ideas why? 有什么想法吗?

Edit 编辑

Was just debugging and called a method in the viewcontroller before calling a pushViewController on it. 只是调试并在调用pushViewController之前在viewcontroller中调用了一个方法。 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. 调试器显示nib名称设置正确,捆绑包为nil(正在传递的内容),但视图也为nil。 No idea why!!! 不知道为什么!

**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. 这是MyThumbnailViewController类的viewDidLoad。 The control never reaches here 控制永远不会到达这里

- (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! 只是重新创建了整个东西,现在它可以正常工作,尽管我看不到两者都有任何不同!

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. 我确定您已经尝试过此方法,但是以防万一您是否在调用方法处理您的pushView之前在该位置设置断点,并逐步执行代码以查看在哪里引发了异常。 This sometimes helps. 这有时会有所帮助。 I'll check back later to see what you find out and to see if I can offer any more help. 稍后我会再检查以查看您的发现,并查看是否可以提供更多帮助。

Sounds strange, but just to be safe maybe double check the following again: Open IB and select File's Owner. 听起来很奇怪,但是为了安全起见,可能再次仔细检查以下内容:打开IB并选择“文件所有者”。 Then in the Identity Inspector make sure the Class is set your custom View Controller. 然后,在Identity Inspector中,确保将Class设置为您的自定义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). 打开连接检查器,并确保视图插座已连接到NIB中的视图(这是异常所抱怨的)。

Save the XIB File and close IB. 保存XIB文件并关闭IB。 Then in XCode select Build->Clean All Targets and try running your app. 然后在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. 我已经看到IB和XCode不止一次地分开,我热切地在IB中编辑视图,因为我没有将它们偶然添加到我的项目中,所以我的应用程序永远不会加载。 So I can feel your pain :-) 所以我可以感觉到你的痛苦:-)

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. 我遇到了同样的错误-到处乱逛之后,我将VIEW OUTLET(在文件所有者中)重新连接到VIEW CONTROLLER中的VIEW(我刚刚连接到VIEW屏幕的主要部分),很抱歉,我是所有这一切的新手,所以我确定并没有用正确的名称来称呼这些东西),并加以解决。 It had worked before, but something I did must have broken that link. 它以前曾经起作用过,但是我做的某些事情一定破坏了该链接。

FogCityFun 雾之城

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iPhone和iPad之间复制Core Data数据库时,为什么会出现写入错误? - Why am I getting a write error when copying a Core Data database between iPhone and iPad? 为什么在安装iPhone应用程序时出现CGContext错误? - Why am I getting CGContext errors when installing an iPhone app? 保存NSManagedObjectContext这个'干净'时为什么会出现合并错误? - Why am I getting a merge error when saving an NSManagedObjectContext this 'clean'? 为什么在加载TableViewcontroller时出现此错误 - Why am I getting this error when loading my TableViewcontroller 为什么我没有得到两个核心位置之间的正确距离? - Why am I not getting the correct distance between two corelocation's? 为什么我会收到sqlite3error? - Why I am getting sqlite3error? 为什么我会收到此 NSManaged Object 错误 - Why Am I Getting This NSManaged Object Error 当我发送到许多请求时,为什么会出现此错误(HTTP错误400)? - Why i am getting this error (HTTP error 400.) when I send to many request? 当我单击按钮时,为什么会出现“无法识别的选择器”错误? - Why am I getting a “unrecognized selector” error when I click on a button? 定义方法后,为什么会收到“无法识别的选择器发送到实例”错误? - Why am I getting an “unrecognised selector sent to instance” error when I have defined the method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM