- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的项目中有一组这样的图片,
我正试图将它们全部放入一个可变数组中,就像这样,
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/
在 viewDidLoad 上,我的应用程序填充 NSMutableArray arrayOfHaiku,它是 NSDictionary 项的数组,如下所示: NSError *error; NS
我在 NSMutableArray 上是这样的: NSMutableArray *array = [NSMutableArray arrayWithObjects:@"0",@"0",@"0",@"0
我正在尝试设置我的 allArticlesArray 的内容,然后将附加对象附加到数组中。这是我的代码片段: [self.allArticlesArray setArray:newsArray]; [
我用 NSMutableArray 中的数据填充了 TableView ,一切正常。当我选择一个单元格(didSelectRowAtIndex)时,该项目将从数组中删除,正如它应该做的那样。现在我希望
我有一个 NSMutableArray 是我的代表,我也在我的一个 View Controller 中使用它。 所以在 viewDidLoad 我像这样制作我的 NSMutableArray 的可变副
我有 100 个元素的 NSMutableArray。 我想将“20 - 50”、“10 - 20”、“60 - 100”和 50 - 60. 元素加载到单独的 NSMutableArray 中,并将
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
我在尝试将字符串的 NSMutableArray 共享给另一个类时遇到了一些问题。我有一个 tableView,其中填充了 Strings,我想将其添加到 NSMutableArray。然后在另一个
正如我们所知,数组是一个连续的内存分配。那么 NSMutableArray 大小将如何增加。 最佳答案 C 数组确实使用连续内存,C++ std::vector 也是如此,但是 NSMutableAr
我需要对一个数组进行排序,里面有一个数组,像这样: NSMutableArray * array_example = [[NSMutableArray alloc] init]; [array_e
这看起来很简单,但我只是得到一个空数组。 我想获取一个按下的按钮,找到它旁边的所有按钮(参见代码中的注释),并将所有找到的按钮添加到另一个 NSMutableArray。 然后我想遍历该数组并对每个按
我正在尝试在另一个 NSMutableArray 中添加 NSMutableArray。但我想做的是嵌套数组。 我当前的代码是: NSMutableArray *array1 = [NSMutab
我有三个类,即DepartmentViewController、DepartmentRequest、Department。这就像我从 DepartmentViewcontroller 发出部门请求,并
我正在尝试将 NSMutableArray 存储在 NSMutableArray 中。所以 var all:NSMutableArray = NSMutableArray() let localArr
这一定是那些错误之一,您一直盯着代码看很长时间,以至于找不到错误。 我有这个代码块,我在其中循环遍历一个包含多个 NSMutableArray 的 NSMutableArray: // FoodVi
我有一个包含 50 个条目的 NSMutableArray - 有什么简单的方法可以将其分成 5 个 NSMutableArray,每个 10 个条目。 最佳答案 是的,要划分 NSMutableAr
我想将 NSMutableArray 的 addObject 放入 NSMutableArray 中,那么我如何快速实现这一点。并检索它,所以请帮助我,因为现在我正在快速学习。 间接说我要二维数组是指
好吧: 我有 NSMutableArray 1 我还有 NSMutableArray 2 我想从数组 1 中删除与数组 2 中的对象匹配的所有对象。 有什么想法吗? 最佳答案 我刚刚打开文档,打印 N
我正在尝试制作 NSMutableArray 的深拷贝,其对象是与此类似的自定义类的实例: @interface CustomParent : NSObject @property NSInteger
我知道你们可能会觉得这是一个重复的问题。但我对我的项目的这个问题搞砸了。 现在转到这个问题,我已经采取了NSMutableArray命名为 arr1包含字符串值,例如 @"34" , @"40"等等。
我是一名优秀的程序员,十分优秀!