在我的应用程序中插入对象的NSMutableArray的时候,我要插入的对象进入的NSMutableArray:奇怪的结果在指数1
NSMutableArray *test = [NSMutableArray arrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:3], [NSNumber numberWithInt:4], nil];
[test insertObject:[NSNumber numberWithInt:2] atIndex:1];
我把断点在第二行代码,结果在调试区OK:
self = (MasterViewController *) 0x074b9cb0
test = (NSMutableArray *) 0x07462c50 @"3 objects"
[0] = (id) 0x07461f10 (int) 1
[1] = (id) 0x07473ec0 (int) 3
[2] = (id) 0x074cbd30 (int) 4
但是运行第二个代码行后,结果是出人意料:
self = (MasterViewController *) 0x074b9cb0
test = (NSMutableArray *) 0x07462c50 @"4 objects"
[0] = (id) 0x074713f0 (int) 2
[1] = (id) 0x07473ec0 (int) 3
[2] = (id) 0x074cbd30 (int) 4
[3] = (id) 0x07461f10 (int) 1
谁能解释为什么在索引1处插入第一个对象(int 1)后成为最后一个对象,或者这种情况是ios 6.1的bug?
当在索引> 1处插入对象时,没有问题。
你在调试区看到这个结果吗?如果你迭代数组呢? – tkanzakic 2013-03-01 07:35:00