Xcode 4.5 损坏 XIB?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11137669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:39:33  来源:igfitidea点击:

Xcode 4.5 corrupting XIBs?

xcodeexceptionuitableviewxibnib

提问by Dima

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

我正在使用新的 xcode 4.5,我在某些视图控制器上有以下代码行:

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?

当我运行应用程序时,它抛出:由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“NIB 数据无效。” 在 LoadNib 线上,那是什么?这个 xcode 是苹果垃圾吗?

回答by tomgerhardt

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

我遇到了同样的问题,并通过取消选中实用工具中文档检查器窗格上的“使用自动布局”复选框来修复它。

回答by aToz

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

取消选中下图中突出显示的“使用自动布局”。Xcode 4.5 默认为您添加到项目中的新 nib 文件启用此属性。取消选中自动布局复选框解决了问题

回答by Symmetric

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.

我刚刚遇到了这个问题,并将其追溯到一个 UIButton,该 UIButton 在属性检查器中将 Title 字段设置为 Attributed。将其更改为 Plain 解决了问题。如果我没记错的话,我在最新版本的 Xcode 中添加了这个按钮,然后也遇到了问题。

回答by Asciiom

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.

对我来说,这是 Jason Coco 的评论和 tomgerhardt 的回答的结合:我的应用程序面向 iOS5,我升级到 Xcode 4.5 并创建了一个新的 NIB。默认情况下,这是针对 iOS6,导致崩溃。我在 NIB 的文件检查器窗口中将其设置为 iOS5。

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.

然后我收到一个编译器错误,告诉我 iOS5 不支持使用自动布局,在文档检查器中打开了,我的问题得到了解决。

回答by Ben

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.

我正在使用 Xcode 4.5 和 iPhone 模拟器 5.0,并且在显示第一个表时出现同样的错误。按照“取消选中自动布局”的建议,我通过将文档版本控制切换到 iOS 5.0 使其工作。(已选择故事板 -> 文件识别选项卡 -> 界面生成器文档 -> 文档版本。)自动版式已取消选择。

回答by CoBrA2168

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.

所以,经过大约一个小时的尝试解决这个问题后,我发现了这个问题。这确实是上面描述的:确保您的 .xib 设置为与您的主应用程序相同的目标版本(在这种情况下,很可能 < 6.0),并在选项中取消选中“使用自动布局”特别是.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.

它可以在模拟器中工作的原因是因为您的模拟器实际上运行的是 iOS6。尝试使用具有较旧 iOS 的设备时,将导致此错误。我的问题是,我正在创建一个自定义 TableViewCell,它默认针对 iOS 6 并选中了“使用自动布局”。这是我的罪魁祸首。

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

希望我能够挽救一个人因这个错误而遭受的悲痛!

回答by Jasper

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.

在为我的所有 .xib 文件禁用自动布局后,我仍然遇到错误。这是因为我在 .xib 文件中为 UILabel 使用了 Text -> Attributed。

After setting it to Plain the error was gone.

将其设置为 Plain 后,错误消失了。

回答by Vladimir

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 ...).

“loadNibNamed:”后面的名称必须是nib文件的名称(在屏幕左侧的项目导航器中),有时人们会在CellForRowAtIndexPath(静态NSString ...)中写入从头开始写入的“单元标识符” .

May be your problem in this little fault?

这个小故障可能是你的问题?