您正在初始化viewDidLoad
,但是你应该这样做init
.
这两者是相似的,并且完全有效。
_scores = [[NSMutableArray alloc] initWithObjects:@0,@0,@0,@0,nil];
or,
self.scores=[[NSMutableArray alloc]initWithObjects:@0,@0,@0, nil];
你的最后一个问题...Then how do I add (NSNumber *)updateValue to, say, the nth value?
If you addObject:
最后会添加。你需要insertObject:atIndex:
在您所需的索引中,所有后续对象将转移到下一个索引。
NSInteger nthValue=12;
[_scores insertObject:updateValue atIndex:nthValue];
EDIT:
编辑后,
NSInteger previousValue = [[_scores objectAtIndex:baseIndex] integerValue];
NSInteger updatedValue = previousValue + scoreAdjustmentAmount;
[_scores replaceObjectAtIndex:baseIndex withObject:[NSNumber numberWithInt:updatedValue]];