我创建了一个NSMutableArray
来存储一些角色。当我在那里添加一些角色时,它给了我一个错误。这是我的代码:
@property(strong,nonatomic) NSMutableArray *actions; < ViewController.h
@synthesize actions; < ViewController.m
actions = [[NSMutableArray alloc]init];
switch ([sender tag]) {
case 0:
currentLabel = water;
[actions insertObject:@"0" atIndex:i];
i++;
break;
case 1:
currentLabel = coke;
[actions insertObject:@"1" atIndex:i];
i++;
break;
case 2:
currentLabel = fanta;
[actions insertObject:@"2" atIndex:i];
i++;
break;
}
答案 0 :(得分:0)
请改用[actions addObject:@"X"]
。如果数组没有元素,则无法在索引1处插入对象。