ios NSInternalInconsistencyException,原因:无法在包中加载 NIB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27842740/
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
NSInternalInconsistencyException, reason: Could not load NIB in bundle
提问by James
I've gone through a bunch of answers regarding this problem but none seem to relate to my problem.
我已经通过了一堆关于这个问题的答案,但似乎没有一个与我的问题有关。
I have two views, View 1 has a button. View 2 has a button.
我有两个视图,视图 1 有一个按钮。视图 2 有一个按钮。
View 1 button is tied to a model segue to View 2.
View 1 按钮绑定到 View 2 的模型转场。
I click the Button in View 1, it opens up View 2.
我单击视图 1 中的按钮,它打开了视图 2。
In View 2 the button is connected to an IBAction which fires
在视图 2 中,按钮连接到一个 IBAction 触发
[self dismissViewControllerAnimated:YES completion:nil];
Which closes the View and displays View 1 again - Now if I press the Button on View 1 again I get
关闭视图并再次显示视图 1 - 现在如果我再次按下视图 1 上的按钮,我会得到
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <x/y/z/SomeApp.app> (loaded)' with name 'tvz-Io-ndz-view-rB8-bq-l6j' and directory 'Main.storyboardc''
I'm completely lost how to fix this problem. Please help!
我完全不知道如何解决这个问题。请帮忙!
EDIT:
编辑:
- This only happens when the device doesn't have internet
- If I have a third screen in the chain with a webview which renders an image, if I goto that screen from View 2 the app doesn't crash.
- 这只发生在设备没有互联网时
- 如果链中的第三个屏幕带有呈现图像的 webview,如果我从 View 2 转到该屏幕,应用程序不会崩溃。
EDIT 2:
编辑2:
I've also tried rebuilding the screen from scratch.
我也试过从头开始重建屏幕。
I'm completely baffled.
我完全不知所措。
EDIT 3: Full Stacktrace
编辑 3:完整的堆栈跟踪
2015-01-19 09:10:58.528 SomeApp[37747:2203364] *** Terminating app due to
uncaught exception 'NSInternalInconsistencyException', reason: 'Could not
load NIB in bundle: 'NSBundle
</Users/user/Library/Developer/CoreSimulator/Devices/D23C1B7C-7330-
466E-8369-762C6727B19C/data/Containers/Bundle/Application/AE67C3D3-C5AE-
4A66-91EC-54D976A4A4FC/SomeApp.app> (loaded)' with name 'tvz-Io-ndz-view-
rB8-bq-l6j' and directory 'Main.storyboardc''
*** First throw call stack:
(
0 CoreFoundation 0x01f64946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01beda97 objc_exception_throw + 44
2 CoreFoundation 0x01f6486d +[NSException raise:format:] + 141
3 UIKit 0x008f8e06 -[UINib instantiateWithOwner:options:] + 1003
4 UIKit 0x0071b624 -[UIViewController _loadViewFromNibNamed:bundle:] + 270
5 UIKit 0x0071bdbb -[UIViewController loadView] + 295
6 UIKit 0x0071bfef -[UIViewController loadViewIfRequired] + 78
7 UIKit 0x0071c595 -[UIViewController view] + 35
8 UIKit 0x00d8f707 -[_UIFullscreenPresentationController _setPresentedViewController:] + 75
9 UIKit 0x006f1a81 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 113
10 UIKit 0x00729a61 -[UIViewController _presentViewController:withAnimationController:completion:] + 2102
11 UIKit 0x0072c5d2 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
12 UIKit 0x0072c424 -[UIViewController presentViewController:animated:completion:] + 224
13 UIKit 0x0072c8ea -[UIViewController presentModalViewController:animated:] + 57
14 UIKit 0x00bf448d -[UIStoryboardModalSegue perform] + 271
15 UIKit 0x00be1b49 -[UIStoryboardSegueTemplate _perform:] + 217
16 UIKit 0x00be1bc5 -[UIStoryboardSegueTemplate perform:] + 116
17 UIKit 0x006d4907 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1490
18 UIKit 0x006d4af7 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 285
19 UIKit 0x006d9df3 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
20 UIKit 0x005ee0ce ___afterCACommitHandler_block_invoke + 15
21 UIKit 0x005ee079 _applyBlockToCFArrayCopiedToStack + 415
22 UIKit 0x005ede8e _afterCACommitHandler + 545
23 CoreFoundation 0x01e879de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
24 CoreFoundation 0x01e87920 __CFRunLoopDoObservers + 400
25 CoreFoundation 0x01e7d35a __CFRunLoopRun + 1226
26 CoreFoundation 0x01e7cbcb CFRunLoopRunSpecific + 443
27 CoreFoundation 0x01e7c9fb CFRunLoopRunInMode + 123
28 GraphicsServices 0x043d524f GSEventRunModal + 192
29 GraphicsServices 0x043d508c GSEventRun + 104
30 UIKit 0x005c48b6 UIApplicationMain + 1526
31 SomeApp 0x000e482d main + 141
32 libdyld.dylib 0x027e8ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
James
詹姆士
回答by Razvan
There can be quite a number of reasons that could raise the error you're receiving.
可能有很多原因可能会引发您收到的错误。
I'll start enumerating some things to check for and solutions:
我将开始列举一些要检查的内容和解决方案:
Have you renamed your xib or storyboard file outside Xcode? If so, check everywhere you have a reference to it for inconsistencies. Also be sure you respect the uppercase / lowercase letters anywhere you reference the file since is case sensitive.
Go to Interface Builder, select your View1 ViewController > Utilities Panel >
Identity Inspector
> check if theCustom Class
corresponds to your ViewController Class if you have one (.h and .m files).Check your
Info.plist
file. If you use storyboads, you should have an entry likeMain storyboard file base name
and NOTMain nib file base name
. If you use nibs, then is vice-versa. Also check that the file base name corresponds with name of the actual file.Check your target's
Build Phases > Copy Bundle Resources
and make sure that your xib or storyboard file is added there.If you instantiate your View1 ViewController programmatically and you use xib file check the nib name for typos (remember, is case-sensitive). Also, if you currently append .xib file format to the name, remove the extension because it shouldn't be used. What I mean is this line of code:
UIViewController *controller = [[UIViewController alloc] initWithNibName:@"xibFileName" bundle:nil];
Check the properties of your xib or storyboard file in the file inspector and make sure that your file is linked to your target in the
Target Membership
selection panel.Check the properties of the xib or storyboard file in the file inspector and try switching your file
Location
toRelative to project
orRelative to group
. See if either way makes a difference.If you're adding your view controller programmatically in the
initWithCoder
then you should instantiate it in theviewDidLoad
method insteadIf nothing from above applies to your situation, you could delete the file from Xcode (select
Remove References
) and import it again in your project.
您是否在 Xcode 之外重命名了您的 xib 或故事板文件?如果是这样,请检查所有引用它的地方是否存在不一致之处。还要确保在引用文件的任何地方尊重大写/小写字母,因为区分大小写。
转到 Interface Builder,选择您的 View1 ViewController > Utilities Panel >
Identity Inspector
> 检查是否Custom Class
对应于您的 ViewController 类,如果您有一个(.h 和 .m 文件)。检查您的
Info.plist
文件。如果您使用故事板,您应该有一个条目,如Main storyboard file base name
和 NOTMain nib file base name
。如果您使用笔尖,则反之亦然。还要检查文件库名称是否与实际文件的名称相对应。检查您的目标
Build Phases > Copy Bundle Resources
并确保您的 xib 或故事板文件已添加到那里。如果您以编程方式实例化 View1 ViewController 并使用 xib 文件,请检查笔尖名称是否有拼写错误(请记住,区分大小写)。此外,如果您当前将 .xib 文件格式附加到名称,请删除扩展名,因为它不应该被使用。我的意思是这行代码:
UIViewController *controller = [[UIViewController alloc] initWithNibName:@"xibFileName" bundle:nil];
在文件检查器中检查您的 xib 或故事板文件的属性,并确保您的文件已链接到
Target Membership
选择面板中的目标。在文件检查器中检查 xib 或故事板文件的属性,然后尝试将文件切换
Location
为Relative to project
或Relative to group
。看看这两种方式是否有所不同。如果您以编程方式在 中添加视图控制器,
initWithCoder
那么您应该在viewDidLoad
方法中实例化它如果以上内容均不适用于您的情况,您可以从 Xcode 中删除该文件(选择
Remove References
)并在您的项目中再次导入它。
Remember to ALWAYS clean your project after making the above changes (SHIFT+COMMAND+K).
请记住在进行上述更改后始终清理您的项目(SHIFT+COMMAND+K)。
Please let us know if it worked and what worked.
请让我们知道它是否有效以及什么有效。
回答by Rishabh Sanghvi
I tried all above answer but they didn't work. For me, the solution was to include the xib to the target resource.
我尝试了以上所有答案,但没有奏效。对我来说,解决方案是将 xib 包含到目标资源中。
Steps performed:
执行的步骤:
- Click on xib file.
- Open Identity Inspector -> Target Membership and check second option (ProjectName_Resource)
- 单击 xib 文件。
- 打开 Identity Inspector -> Target Membership 并检查第二个选项 (ProjectName_Resource)
回答by kpoustas
I faced this when I extracted a .app from a zip file and attempted to run it, both on an iOS device and on Simulator.
当我从 zip 文件中提取 .app 并尝试在 iOS 设备和模拟器上运行它时,我遇到了这个问题。
One .nib file had been named with non-latin characters (fileNormal.nib
with the greek letters No
) and when extracted from the zip, it was assigned letters from another charset (it should be Greek-DOS or something compatible). I chose a different charset upon extraction and it worked as it should.
一个 .nib 文件被命名为非拉丁字符(fileNormal.nib
带有希腊字母No
),当从 zip 中提取时,它被分配了另一个字符集的字母(它应该是希腊-DOS 或兼容的东西)。我在提取时选择了不同的字符集,它可以正常工作。
Just putting this in case someone else faces the same problem ;)
只是为了以防其他人面临同样的问题;)
回答by Mukund Agarwal
You may have to setup the bundle for the class before accessing the xib:
在访问 xib 之前,您可能必须为该类设置包:
ObjectiveC:
目标C:
//Bundle initialisation
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
//Initialising the nib
UIView *nibView = [[bundle loadNibNamed:@"nibFileName" owner:self options:nil] objectAtIndex:0];
//Display the ad (this will vary based on your application setup)
[[[UIApplication sharedApplication] keyWindow] addSubview:nibView];
回答by Hussain Shabbir
回答by user1232690
In my case exact same exception was caused by the fact that two controllers had same storyboard id (within one storyboard)
在我的情况下,完全相同的异常是由两个控制器具有相同的故事板 ID(在一个故事板内)这一事实引起的
回答by peterdoesco.de
It's also possible the UITableViewDataSource or UITableViewDelegate are not implemented in the desired UIViewController
也有可能 UITableViewDataSource 或 UITableViewDelegate 未在所需的 UIViewController 中实现
回答by Eden
If you're working with cocoapods, it may also help to run pod update
. One of my teammates changed a pod around which resulted in that error, so pod update fixed it for me.
如果您正在使用 cocoapods,运行pod update
. 我的一个队友改变了一个 pod,导致了那个错误,所以 pod update 为我修复了它。