libc++abi.dylib:以NSException类型的未捕获异常终止:获取此线程



>2016-02-09 11:25:11.773 TableView[1408:94586] * 由于未捕获的异常"NSRangeException"而终止应用程序,原因:"* -[NSArray0 objectAtIndex:]:索引 0 超出空 NSArray 的边界"第一个抛出调用堆栈:( 0 核心基金会 0x0000000111c5fe65 __exceptionPreprocess + 165 1 利比亚博博杰克。A.迪利布 0x00000001116d6deb objc_exception_throw + 48 2 核心基金会 0x0000000111c0e395 -[__NSArray0 对象索引:] + 101 3 表视图 0x000000010f949046 -[航班详情视图控制器加载信息编辑] + 310 4 表视图0x000000010f94887d -[航班详细信息视图控制器视图DidLoad] + 509 5 UIKit 0x0000000110348f98 -[UIViewController loadViewIfRequired] + 1198 6 UIKit 0x000000011034ef4f -[UIViewController __viewWillAppear:] + 120 7 UIKit 0x000000011037ee44 -[UINavigationController _startCustomTransition:] + 1203 8 UIKit 0x000000011038f23f -[UINavigationController _startDeferredTransitionIfNeeded:] + 712 9 UIKit 0x00000001103903af -[UINavigationController __viewWillLayoutSubviews] + 57 10 UIKit 0x0000000110536ff7 -[UILayoutContainerView layoutSubviews] + 248 11 UIKit 0x00000001102694a3 -[UIView(CALayerDelegate( layoutSublayersOfLayer:] + 703 12 石英芯0x000000011507759a -[CALayer 布局子图层] + 146 13 石英芯 0x000000011506be70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 14 石英芯 0x000000011506bcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 15 石英芯 0x0000000115060475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 16 石英芯 0x000000011508dc0a _ZN2CA11Transaction6commitEv + 486 17 UIKit 0x00000001101ddb47 _afterCACommitHandler + 174 18 核心基金会 0x0000000111b8b367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 19 核心基金会 0x0000000111b8b2d7 __CFRunLoopDoObservers + 391 20 核心基金会 0x0000000111b80f2b __CFRunLoopRun + 1147 21 核心基金会 0x0000000111b80828 CFRunLoopRunspecific + 488 22 图形服务 0x0000000114b2aad2 GSEventRunModal + 161 23 UIKit 0x00000001101b2610 UIApplicationMain + 171 24 表视图 0x000000010f94855f 主 + 111 25 libdyld.dylib 0x00000001126f292d start + 1)libc++abi.dylib:以 NSException 类型的未捕获异常终止(分行(

正如其他人所提到的(并且您的输出清楚地表明(,您的 NSArray 是空的。如果您尝试从不存在的 NSArray 引用索引,它每次都会崩溃。

显然,您正在尝试访问索引 0 处的对象。您可以错误地检查数组是否至少具有作为索引号的项目数:

NSArray *myArray = [NSArray arrayWithObject:@"foo"];
int indexDesired = 0; //since you were attempting to access index 0
long indexCount = [myArray count];
if (indexCount > indexDesired) { //check to make sure index exists
    id myObject = [myArray objectAtIndex:indexDesired];
}

最新更新