在我的應用程序中插入對象的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