Ios 由于未捕获异常而终止应用程序';nsrange异常';,原因:';***-[u NSArrayI objectAtIndex:]:索引1超出范围[0..0]';
我的iOS应用程序有问题。我已经用故事板和一些代码构建了我的应用程序。最初,我有一个TableView,它在第一个选项卡中显示一些内容。现在,我想将此内容放在另一个选项卡中,但当我编辑故事板时,会出现以下错误:Ios 由于未捕获异常而终止应用程序';nsrange异常';,原因:';***-[u NSArrayI objectAtIndex:]:索引1超出范围[0..0]';,ios,objective-c,uncaught-exception,Ios,Objective C,Uncaught Exception,我的iOS应用程序有问题。我已经用故事板和一些代码构建了我的应用程序。最初,我有一个TableView,它在第一个选项卡中显示一些内容。现在,我想将此内容放在另一个选项卡中,但当我编辑故事板时,会出现以下错误: 2013-11-28 17:31:17.354 devis_centrage[13961:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI ob
2013-11-28 17:31:17.354 devis_centrage[13961:70b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x0173a5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bd8b6 objc_exception_throw + 44
2 CoreFoundation 0x016ee9c2 -[__NSArrayI objectAtIndex:] + 210
3 CoreFoundation 0x017b9608 -[NSArray objectAtIndexedSubscript:] + 40
4 devis_centrage 0x000022f8 -[AppDelegate application:didFinishLaunchingWithOptions:] + 936
5 UIKit 0x00225355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
6 UIKit 0x00225b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
7 UIKit 0x0022a3a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
8 UIKit 0x0023e87c -[UIApplication handleEvent:withNewEvent:] + 3447
9 UIKit 0x0023ede9 -[UIApplication sendEvent:] + 85
10 UIKit 0x0022c025 _UIApplicationHandleEvent + 736
11 GraphicsServices 0x036e12f6 _PurpleEventCallback + 776
12 GraphicsServices 0x036e0e01 PurpleEventCallback + 46
13 CoreFoundation 0x016b5d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
14 CoreFoundation 0x016b5a9b __CFRunLoopDoSource1 + 523
15 CoreFoundation 0x016e077c __CFRunLoopRun + 2156
16 CoreFoundation 0x016dfac3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x016df8db CFRunLoopRunInMode + 123
18 UIKit 0x00229add -[UIApplication _run] + 840
19 UIKit 0x0022bd3b UIApplicationMain + 1225
20 devis_centrage 0x00002ccd main + 141
21 libdyld.dylib 0x01d7870d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
下面是阵列初始化的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_aircraft = [NSMutableArray arrayWithCapacity:20];
Aircraft *aircraft = [[Aircraft alloc] init];
aircraft.name = @"Robin DR400";
aircraft.immat = @"F-HAZA";
[_aircraft addObject:aircraft];
aircraft = [[Aircraft alloc] init];
aircraft.name = @"Tecnam P2002 JF";
aircraft.immat= @"F-HAZB";
[_aircraft addObject:aircraft];
aircraft = [[Aircraft alloc] init];
aircraft.name = @"Tecnam P2002 JF";
aircraft.immat= @"F-HAZC";
[_aircraft addObject:aircraft];
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [tabBarController viewControllers][0];
AircraftViewController *aircraftViewController = [navigationController viewControllers][0];
aircraftViewController.aircraft = _aircraft;
return YES;
}
您正在访问数组中的第二个对象。如果您尝试访问它,那么您可以将它(对象)添加到数组中。可能您忘记初始化了。您在
应用程序:didfishlaunchingwithoptions:
中尝试访问的一个数组是空的。您分配并初始化了数组了吗?您能将代码发布到创建数组的位置以及向其中添加项目的位置吗?符号化崩溃报告,它将向您显示应用程序中的确切行:didfishlaunchingwithoptions:
方法,该方法导致数组访问错误。我已经编辑了帖子并添加了数组初始化代码,谢谢!该错误表示您访问了索引1
,但您发布的代码没有引用索引1
,只是0
。同样,对崩溃报告进行符号化处理,以便准确知道是哪一行代码导致了问题。数组不是空的。它有一个目标。这就是有效范围为0到0的原因。