gpt4 book ai didi

ios - NSMutableArray addObject 在设备中崩溃但在模拟器中运行良好

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:47 26 4
gpt4 key购买 nike

我的项目中有一组这样的图片,

enter image description here

我正试图将它们全部放入一个可变数组中,就像这样,

NSMutableArray *imageArray = [[[NSMutableArray alloc] initWithCapacity:36] retain];
for (int i = 0; i < 36; i++) {
UIImage *image = [[UIImage imageNamed:[NSString stringWithFormat:@"quicktour_%d.JPG",i+1]] autorelease];
[imageArray addObject:image];
}

这在模拟器中运行得很好,但当我在添加大约 5 张图像后在设备中运行时崩溃。

它是一个非 ARC 项目。我在 SO 上浏览了所有类似的问题并尝试了那里发布的解决方案,但我的问题仍然存在。

谁能帮帮我?

提前致谢。

编辑:

这是崩溃时在控制台中显示的输出。

***** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' * First throw call stack: (0x2f784f4b 0x39bc56af 0x2f6bec81 0x138987 0x31f2c713 0x31f2c6b3 0x31f2c691 0x31f1811f 0x31f2c107 0x31f2bdd9 0x31f26e65 0x31efc79d 0x31efafa3 0x2f750183 0x2f74f653 0x2f74de47 0x2f6b8c27 0x2f6b8a0b 0x343df283 0x31f5c049 0x1f9ab 0x3a0cdab7) libc++abi.dylib: terminating with uncaught exception of type NSException**

最佳答案

根据文档,传递给 addObject: 的对象 不能为 nil。很有可能您的第五张图片的命名方式与您要求的大小写不匹配,因此 imageNamed: 调用返回 nil。 iOS 文件系统区分大小写,但 OS X 文件系统(通常)不区分大小写;仅出现在设备上的问题通常与此事实有关。

您可以修复文件名以防止崩溃,但您确实应该在将对象添加到数组之前检查代码是否为 nil。

关于ios - NSMutableArray addObject 在设备中崩溃但在模拟器中运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21578913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com