嗨,我早些时候做了一些测试,我的应用程序运行得很好。我想做更多的测试,所以我决定从我的设备中删除该应用程序,然后通过运行重新安装它。
好吧,现在由于某种原因,我进入了我的启动屏幕出现的阶段,然后它崩溃了,我得到了错误:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
这显然意味着数组越界正确吗?但是为什么现在以及我如何才能知道这发生在哪里和哪个视图控制器上?当我尝试通过再次运行它来重新安装应用程序时,它怎么会突然运行,我得到这个错误?
谢谢
编辑 错误与以下代码中的数组有关
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
exploreViewController *view1 = [[exploreViewController alloc] initWithNibName:@"exploreViewController" bundle:nil];
view1.title= @"Explore";
Upcoming *view2 = [[Upcoming alloc] initWithNibName:@"Upcoming" bundle:nil];
view2.title = @"Upcoming";
calcViewController *view3 = [[calcViewController alloc] initWithNibName:@"calcViewController" bundle:nil];
view3.title = @"Calc";
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:view1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:view2];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:view3];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nil];
self.tabBarItem = [[[UITabBarItem alloc] init] autorelease];
NSArray *tabBarItems = self.tabBarController.tabBar.items;
UIImage *tab1 = [UIImage imageNamed:@"85-trophy.png"];
UIImage *tab2 = [UIImage imageNamed:@"12-eye.png"];
UIImage *tab3 = [UIImage imageNamed:@"237-key.png"];
NSArray *tabBarImages = [[[NSArray alloc] initWithObjects:tab1, tab2, tab3,nil]autorelease];
NSInteger tabBarItemCounter;
for (tabBarItemCounter = 0; tabBarItemCounter < [tabBarItems count]; tabBarItemCounter++)
{
tabBarItem = [tabBarItems objectAtIndex:tabBarItemCounter];
tabBarItem.image = [tabBarImages objectAtIndex:tabBarItemCounter];
}