我正在使用Xcode6。我正在学习一个教程,该教程解释了如何使用标签栏控制器和表视图。教程的第一部分做得很好,然后添加了一个额外的控制器并运行了该应用程序后,在控制台中出现以下错误:
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法在名称为'Mrk-WH-vzE-view-zyB-06-j66的捆绑软件:'NSBundle(已加载)'中加载NIB”
然后,我创建了一个全新的项目,只添加了麻烦的额外控制器。问题仍然存在。我进行了一些调试,发现代码到达此特定行时崩溃:
self.items = [NSMutableArray array];
在头文件中,我声明:
@property (nonatomic) NSMutableArray *items;
如有必要,我可以提供.m文件的所有代码。
奇怪的是,在我从教程重新创建的第一个项目中,这段代码在某个类中有效;当我添加第二个类并将相同的代码放入其中时,该应用程序开始崩溃(在第二个类中崩溃)。
我不确定所提供的信息是否足够–如果不足够,请告诉我。
更新:
好的,我有一些新信息。我决定准备代码并将其发布在此处。我开始评论一些东西,以查看可以发布的内容和不相关的内容。
我发现并不是完全导致崩溃的那行(我使用F6而不是F7)。我意识到,在那一行之后,代码转到了另一个函数
- (void)setItems:(NSMutableArray *)items {
if (_items != items) {
_items = items;
// Build Shopping List
[self buildShoppingList];
}}
- (void)buildShoppingList {
NSMutableArray *buffer = [[NSMutableArray alloc] init];
for (int i = 0; i < [self.items count]; i++) {
Item *item = [self.items objectAtIndex:i];
if ([item inShoppingList]) {
// Add Item to Buffer
[buffer addObject:item];
}
}
// Set Shopping List
self.shoppingList = [NSArray arrayWithArray:buffer]; }
- (void)setShoppingList:(NSArray *)shoppingList {
if (_shoppingList != shoppingList) {
_shoppingList = shoppingList;
// Reload Table View
[self.tableView reloadData];
}}
而且代码似乎在行崩溃
[self.tableView reloadData];
我想这是完全不同的情况。
代码首先在setItems中,然后在以下函数中
/// 12月22日更新
我找不到崩溃日志,但这是堆栈跟踪
* thread #1: tid = 0x7e4a, 0x00000001065bbb8a libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x00000001065bbb8a libobjc.A.dylib`objc_exception_throw
frame #1: 0x0000000106922e6d CoreFoundation`+[NSException raise:format:] + 205
frame #2: 0x0000000106fd48c3 UIKit`-[UINib instantiateWithOwner:options:] + 552
frame #3: 0x0000000106e33f98 UIKit`-[UIViewController _loadViewFromNibNamed:bundle:] + 242
frame #4: 0x0000000106e34588 UIKit`-[UIViewController loadView] + 109
frame #5: 0x0000000106ff1368 UIKit`-[UITableViewController loadView] + 76
frame #6: 0x0000000106e347f9 UIKit`-[UIViewController loadViewIfRequired] + 75
frame #7: 0x0000000106e34c8e UIKit`-[UIViewController view] + 27
frame #8: 0x0000000106ff10e3 UIKit`-[UITableViewController tableView] + 30
frame #9: 0x000000010608caf0 Prova`-[ShoppingListViewController setShoppingList:](self=0x00007fa5c3d32b70, _cmd=0x000000010608d754, shoppingList=0x00007fa5c3f03d90) + 112 at ShoppingListViewController.m:75
frame #10: 0x000000010608ca50 Prova`-[ShoppingListViewController buildShoppingList](self=0x00007fa5c3d32b70, _cmd=0x000000010608d70c) + 400 at ShoppingListViewController.m:67
frame #11: 0x000000010608c8a0 Prova`-[ShoppingListViewController setItems:](self=0x00007fa5c3d32b70, _cmd=0x000000010c0eaaea, items=0x00007fa5c3d2fc90) + 112 at ShoppingListViewController.m:51
frame #12: 0x000000010608cf20 Prova`-[ShoppingListViewController loadItems](self=0x00007fa5c3d32b70, _cmd=0x000000010608d6a8) + 288 at ShoppingListViewController.m:111
frame #13: 0x000000010608c6fd Prova`-[ShoppingListViewController initWithCoder:](self=0x00007fa5c3d32b70, _cmd=0x00000001087b740f, aDecoder=0x00007fa5c5828600) + 189 at ShoppingListViewController.m:28
frame #14: 0x0000000106fd59dd UIKit`-[UIClassSwapper initWithCoder:] + 205
frame #15: 0x000000010713a6c6 UIKit`UINibDecoderDecodeObjectForValue + 705
frame #16: 0x000000010713a895 UIKit`UINibDecoderDecodeObjectForValue + 1168
frame #17: 0x000000010713a3fc UIKit`-[UINibDecoder decodeObjectForKey:] + 276
frame #18: 0x0000000106e317aa UIKit`-[UIViewController initWithCoder:] + 927
frame #19: 0x0000000106e53ec4 UIKit`-[UINavigationController initWithCoder:] + 51
frame #20: 0x000000010713a6c6 UIKit`UINibDecoderDecodeObjectForValue + 705
frame #21: 0x000000010713a895 UIKit`UINibDecoderDecodeObjectForValue + 1168
frame #22: 0x000000010713a3fc UIKit`-[UINibDecoder decodeObjectForKey:] + 276
frame #23: 0x0000000106e317aa UIKit`-[UIViewController initWithCoder:] + 927
frame #24: 0x0000000106e704aa UIKit`-[UITabBarController initWithCoder:] + 51
frame #25: 0x000000010713a6c6 UIKit`UINibDecoderDecodeObjectForValue + 705
frame #26: 0x000000010713a3fc UIKit`-[UINibDecoder decodeObjectForKey:] + 276
frame #27: 0x0000000106fd55d6 UIKit`-[UIRuntimeConnection initWithCoder:] + 153
frame #28: 0x000000010713a6c6 UIKit`UINibDecoderDecodeObjectForValue + 705
frame #29: 0x000000010713a895 UIKit`UINibDecoderDecodeObjectForValue + 1168
frame #30: 0x000000010713a3fc UIKit`-[UINibDecoder decodeObjectForKey:] + 276
frame #31: 0x0000000106fd4a79 UIKit`-[UINib instantiateWithOwner:options:] + 990
frame #32: 0x000000010725e572 UIKit`-[UIStoryboard instantiateViewControllerWithIdentifier:] + 181
frame #33: 0x0000000106d0eb92 UIKit`-[UIApplication _loadMainStoryboardFileNamed:bundle:] + 65
frame #34: 0x0000000106d0dc19 UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1075
frame #35: 0x0000000106d0cbf2 UIKit`-[UIApplication workspaceDidEndTransaction:] + 179
frame #36: 0x00000001094de2a3 FrontBoardServices`__31-[FBSSerialQueue performAsync:]_block_invoke + 16
frame #37: 0x000000010685853c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
frame #38: 0x000000010684e285 CoreFoundation`__CFRunLoopDoBlocks + 341
frame #39: 0x000000010684e045 CoreFoundation`__CFRunLoopRun + 2389
frame #40: 0x000000010684d486 CoreFoundation`CFRunLoopRunSpecific + 470
frame #41: 0x0000000106d0c669 UIKit`-[UIApplication _run] + 413
frame #42: 0x0000000106d0f420 UIKit`UIApplicationMain + 1282
frame #43: 0x000000010608d428 Prova`main(argc=1, argv=0x00007fff59b73390) + 184 at main.m:15
frame #44: 0x0000000108eb2145 libdyld.dylib`start + 1
线
[self.tableView reloadData];
对应于
frame #9: 0x000000010608caf0 Prova`-[ShoppingListViewController setShoppingList:](self=0x00007fa5c3d32b70, _cmd=0x000000010608d754, shoppingList=0x00007fa5c3f03d90) + 112 at ShoppingListViewController.m:75
表格视图的代表是
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.shoppingList count];
}
self.shoppingList应该是一个包含0个元素的数组。但是代码似乎没有达到要求
return [self.shoppingList count];
因为它在行前停止
[self.tableView reloadData];
我还认为嵌入此崩溃类的导航控制器可能是负责任的,因此我将其删除,并将主选项卡栏控制器直接连接到具有自定义类的该项目,但未进行任何更改,始终出现相同的错误
最佳答案
我还有另一个更新。今天,我更换了计算机,因此再次下载了xcode并尝试运行该项目...。它的工作原理...我不明白为什么,这些天来有新的Xcode版本吗?
关于ios - Xcode 6“由于未捕获的异常而终止应用程序”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27568137/