Xcode 4.5 corrupting XIBs?

本秂侑毒 提交于 2019-12-17 23:02:43

问题


i am using the new xcode 4.5, i have this lines of code on some view controller:

DiscoverCell* cell=[table dequeueReusableCellWithIdentifier:@"DiscoverCell"];
if(cell==nil){
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DiscoverCell" 
                                                 owner:self 
                                               options:nil];
    cell = [nib objectAtIndex:0];
} 

when i run the app its throwing: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The NIB data is invalid.' on the LoadNib line, what is that? does this xcode is some apple garbage?


回答1:


Uncheck the "use Autolayout" highlighted in the below image. Xcode 4.5 enables this property by default for the new nib files you add into your project. Unchecking the autolayout check box solved the problem




回答2:


I had this same issue and fixed it by unchecking the 'Use Autolayout' checkbox on the Document Inspector pane in Utilities.




回答3:


I just had this problem and tracked it down to a UIButton that had the Title field set to Attributed in the Attributes Inspector. Changing this to Plain fixed the problem. If I remember correctly I added this button in the last version of Xcode and had trouble with it then also.




回答4:


For me it was a combination of the comment by Jason Coco and the answer by tomgerhardt: My app targets iOS5, I upgraded to Xcode 4.5 and created a new NIB. By default this targeted iOS6, causing a crash. I set this to iOS5 in the NIB's file inspector window.

Then I got a compiler error that told me Use Autolayout wasn't supported for iOS5, turned that of in the Document inspector and my issue was fixed.




回答5:


I am using Xcode 4.5 and iPhone simulator 5.0 and it this same error when the first Table was displayed. Following the 'uncheck autolayout' advice, I got it working by Switching the Document Versioning to iOS 5.0. (Storyboard selected -> File Identify tab -> Interface Builder Document -> Document Versioning.) The AutoLayout was already unselected.




回答6:


So, after about an hour of trying to figure this out, I figured out the issue. It is indeed what is described above: make sure your .xib is set to the same target version (in this case, most likely < 6.0) as what your main app was written for, and uncheck "Use Autolayout" in the options for this particular .xib.

The reason it will work in the simulator, is because your simulator actually is running iOS6. When trying to use a device with an older iOS, will result in this error. My problem was, I was creating a custom TableViewCell which by default was targeted for iOS 6 and had the "Use Autolayout" checked. This was the culprit for me.

Hopefully I'm able to save someone out there the grief I was put through with this error!




回答7:


After disabling Auto-Layout for all my .xib files I still had the error. This was due to the fact I used Text -> Attributed for a UILabel in a .xib file.

After setting it to Plain the error was gone.




回答8:


The name after "loadNibNamed:" must be the name of the nib file (in project navigator on the left side of the screen), sometimes people write there 'cell identifier' that writes from the start in CellForRowAtIndexPath (static NSString ...).

May be your problem in this little fault?



来源:https://stackoverflow.com/questions/11137669/xcode-4-5-corrupting-xibs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!