45

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?

Dima
  • 8,586
  • 4
  • 28
  • 57
  • I've got the same issue when I try to start Apps, with NIBs inside, on an iOS 5.1 Device...(When I start the App in the Simulator everything works.) My workaround is using Xcode 4.4... – Lindemann Jun 27 '12 at 15:51
  • 10
    Using the file utility panel on the right side, make sure your NIB's project target is set to iOS 5 if that's your deployment target. By default this is set at project which is iOS 6 in Xcode 4.5 and it will make changes and save the nib in a non-backward compatible way. Change all your nibs to the actual iOS version for deployment and save. – Jason Coco Jul 03 '12 at 05:44
  • if you are using iOS6 make sure to see this post http://stackoverflow.com/questions/12411980/enabling-auto-layout-in-ios-6-while-remaining-backwards-compatible-with-ios-5 – Kassem Oct 10 '12 at 13:09
  • I have the same problem but I know that's a problem. If it's already unselected, then select, save and run, stop unselected, then save and run again. In my case that made it work. –  Nov 08 '12 at 06:17
  • hey @dima , this was a nice question and beautiful one just like you. – YogiAR Nov 21 '12 at 12:19

8 Answers8

71

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

tomgerhardt
  • 711
  • 1
  • 4
  • 5
58

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

aToz
  • 2,463
  • 1
  • 24
  • 34
8

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.

Symmetric
  • 4,013
  • 3
  • 27
  • 33
6

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.

Asciiom
  • 9,867
  • 7
  • 38
  • 57
4

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.

Ben
  • 41
  • 1
2

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!

CoBrA2168
  • 418
  • 3
  • 12
2

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.

Jasper
  • 7,031
  • 3
  • 35
  • 43
0

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?

Vladimir
  • 13
  • 3