iphone - iOS 在 didFinishLaunchingWithOptions : index 0 beyond bounds for empty array 之前崩溃

标签 iphone ios exception

更新

这个问题我自己解决了。我把它放在这里以供进一步引用。我发现我将窗口的 rootViewController 连接到 MainWindow.xib 中的 tabBarController,而不是在 didFinishLaunchingWithOptions 中添加以下行>:

[self.window setRootViewController:self.tabBarController];

删除主窗口中的链接后一切正常。

我猜它可能会触发第一个选项卡的 View ,该选项卡有一个未初始化的数组。

反正我还是不明白为什么ios4下可以。

谢谢。

enter image description here

<小时/>

更新

感谢您的评论和回答,它发生在进入 didFinishLaunchingWithOptions 之前。但是我仍然将 didFinishLaunchingWithOptions 粘贴到此处,看看我是否错过了任何内容。

ps:在 ios 4.x 上完美运行

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    return YES;
}
<小时/>

嗨,我遇到了一个奇怪的问题,发生在 didFinishLaunchingWithOptions 之前,所以我不知道如何处理它。谁能给出任何提示吗?谢谢你。

2012-03-10 18:03:12.642[95579:17003] Unresolved error (null), (null)
2012-03-10 18:03:12.644[95579:17003] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1a07052 0x1fbbd0a 0x19f3db8 0x16c57 0x19d15 0x973e 0x8665 0xa1a64e 0xa19c1c 0xa4056d 0xa2ad47 0xa41441 0xa4145d 0xa4145d 0xa414f9 0x981d65 0x981dac 0xb7274e 0xb74010 0x95414a 0x954461 0x9537c0 0x962743 0x9631f8 0x956aa9 0x28f4fa9 0x19db1c5 0x1940022 0x193e90a 0x193ddb4 0x193dccb 0x9532a7 0x954a9b 0x2690 0x1eb5)
terminate called throwing an exceptionCurrent language:  auto; currently objective-c

最佳答案

首先检查数组是否为空:

if ([array count] > 0) {
/* do something with your array */
}

如果需要查看数组内部,请设置断点并在调试时查看内部​​。

关于iphone - iOS 在 didFinishLaunchingWithOptions : index 0 beyond bounds for empty array 之前崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9644616/

相关文章:

ios - Xcode:我用 CocoaPods 添加的 AWS SDK 不起作用?

android - 如何防止android应用程序崩溃

iPhone将字符串分成多行并显示为标签

iphone - 静态库具有相同的函数名称导致重复符号错误

iphone - 如何在 Google Analytics for iOS 中设置页面标题?

iphone - 初学者 : Multiview app doesn't switch views correctly

ios - Facebook 发送应用程序进行审核,我如何生成免费的隐私政策?

ios - Sprite Kit 停止脉冲

java.lang.ArithmeticException 在没有堆栈跟踪和消息的情况下抛出

c++ - 如果set_terminate中的处理程序不中止怎么办?