removeObject有效,但addObject没有,两者都有相同的参数

时间:2016-08-29 08:47:10

标签: objective-c

在下面的代码中,removeObject工作正常,但addObject不起作用。有什么问题?

[randomizedList addObject:sourceList[index]];

randomizedList在执行NSArray > NAObject >isa Class 0x0之前和之后是相同的:$msgemail

1 个答案:

答案 0 :(得分:3)

此处的问题是randomizedList未分配。

NSMutableArray *sourceList = self.questions;
NSMutableArray *randomizedList = [[NSMutableArray alloc] init];

for (NSInteger i = sourceList.count; i > 0; i--) {
    //other things

    [randomizedList addObject:sourceList[index]];
    [sourceList removeObject:sourceList[index]];
}
相关问题