xcode 无法在包中加载 NIB:'NSBundle 使用故事板时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8689235/
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-14 22:52:03  来源:igfitidea点击:

Could not load NIB in bundle: 'NSBundle when using storyboarding

iphoneiosxcodeuistoryboard

提问by stubble jumper

I am getting the following error when I use my app for a little while. Usually takes between 50 and 100 movements to cause the crash. I am not making sense of it though as I am using storyboards, and it is a NIB error.

当我使用我的应用程序一段时间时出现以下错误。通常需要 50 到 100 次移动才能导致崩溃。虽然我使用的是故事板,但我没有理解它,这是一个 NIB 错误。

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 
'Could not load NIB in bundle: 'NSBundle 
</Users/me/Library/Application Support/iPhone Simulator/5.0/Applications/GUID/appname.app>
(loaded)' with name 'MainStoryboard_iPhone.storyboardc/q8p-MH-tsT-view-acD-hJ-g0C''

I am not 100% sure where to begin looking, but I assume that this means that the storyboard is corrupt?

我不是 100% 确定从哪里开始寻找,但我认为这意味着故事板已损坏?

I looked through all of my source, and I don't have the string "nib" anywhere, so there are no nibWithNibName calls or the like. I also don't have a MainWindow.xib, though I tried creating one. I am not sure if it can be set to the main interface when I am using storyboards though. There is one reference to a .nib in the .xcodeproj/project.pbxproj file, however:

我查看了我的所有源代码,并且在任何地方都没有字符串“nib”,因此没有 nibWithNibName 调用等。我也没有 MainWindow.xib,但我尝试创建一个。我不确定当我使用故事板时是否可以将它设置为主界面。但是,在 .xcodeproj/project.pbxproj 文件中有一个对 .nib 的引用:

/* Begin PBXBuildRule section */
148BDD4C14AE8D5E002C30ED /* PBXBuildRule */ = {
    isa = PBXBuildRule;
    compilerSpec = com.apple.compilers.proxy.script;
    fileType = wrapper.nib;
    isEditable = 1;
    outputFiles = (
    );
    script = "$(DEVELOPER_BIN_DIR)/ibtool\n";
};

I am using storyboarding in Xcode 4.2. My main storyboard is set to MainStoryboard_iPhone, and its file is named MainStoryboard_iPhone.storyboard.

我在 Xcode 4.2 中使用故事板。我的主故事板设置为 MainStoryboard_iPhone,其文件名为 MainStoryboard_iPhone.storyboard。

The crash is in the iOS 5 simulator.

崩溃发生在 iOS 5 模拟器中。

回答by DaiZW

I got exactly this error, too.

我也遇到了这个错误。

Finally I found the cause was I accessed self.tableViewin -(id)initWithCoder:(NSCoder *)aDecoderbefore it was initiated.

最后我发现原因是我self.tableView-(id)initWithCoder:(NSCoder *)aDecoder启动之前访问了它。

So, I moved those code into - (void)viewDidLoad, everything went well.

所以,我把这些代码移到了- (void)viewDidLoad,一切顺利。

回答by Greg Steiner

This question appears to have been answered in the comments area. Reposting here so question shows as having an answer. -- gs.

这个问题似乎已经在评论区得到了回答。在此处重新发布,因此问题显示为有答案。——gs。

Answer copied from comments:

从评论中复制的答案:

There was a memory leak in a 3rd party component. Once the resources were exhausted, it would crash with the error above. A couple weeks of QA/Beta testing confirmed that it is gone. Thanks. – stubble jumper Jan 24 at 2:29

第 3 方组件中存在内存泄漏。一旦资源耗尽,它就会因上述错误而崩溃。几周的 QA/Beta 测试证实它已经消失了。谢谢。– 1 月 24 日 2:29 的茬跳投

回答by abriggs

I've had this problem before. The name of my nib was different than the name of my view controller while using - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNilas my init.

我以前遇到过这个问题。- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil用作初始化程序时,笔尖的名称与视图控制器的名称不同。