アプリの実行時に呼び出される(id)タイプの関数で定義された「スコア」nsmutable配列でスコアを更新しようとしているだけです。そのため、何が問題なのかわかりません。関数の本体の前と後に NSLog を配置して、何が起こっているかを確認し、コードの後に投稿します。
-(void)changeScore:(int)moves AtLevel:(int)theLevel{
for (int i = 0; i < 20; i++) {
NSLog(@"At level %d we have a score of: %d ", i+1, [[scores objectAtIndex:i] intValue]);
}
if (theLevel <= 9){
NSNumber* number = [[NSNumber alloc]initWithInt:50 - moves];
[scores replaceObjectAtIndex:theLevel - 1 withObject:number];
NSLog(@"this is number's int value: %d and this is thelevel - 1: %d", [number intValue], theLevel - 1);
}
if (theLevel > 9 && theLevel <= 19){
NSNumber* number = [[NSNumber alloc]initWithInt:150-moves];
[scores replaceObjectAtIndex:theLevel - 1 withObject:number];
}
for (int i = 0; i < 20; i++) {
NSLog(@"At level %d we have a score of: %d", i+1, [[scores objectAtIndex:i] intValue]);
}
}
そして NSLog はこれを生成します:
2012-04-14 14:53:49.018 Arctic Defender[2068:f803] At level 1 we have a score of: 0
2012-04-14 14:53:49.022 Arctic Defender[2068:f803] At level 2 we have a score of: 0
2012-04-14 14:53:49.023 Arctic Defender[2068:f803] At level 3 we have a score of: 0
2012-04-14 14:53:49.024 Arctic Defender[2068:f803] At level 4 we have a score of: 0
2012-04-14 14:53:49.026 Arctic Defender[2068:f803] At level 5 we have a score of: 0
2012-04-14 14:53:49.027 Arctic Defender[2068:f803] At level 6 we have a score of: 0
2012-04-14 14:53:49.028 Arctic Defender[2068:f803] At level 7 we have a score of: 0
2012-04-14 14:53:49.029 Arctic Defender[2068:f803] At level 8 we have a score of: 0
2012-04-14 14:53:49.030 Arctic Defender[2068:f803] At level 9 we have a score of: 0
2012-04-14 14:53:49.031 Arctic Defender[2068:f803] At level 10 we have a score of: 0
2012-04-14 14:53:49.032 Arctic Defender[2068:f803] At level 11 we have a score of: 0
2012-04-14 14:53:49.033 Arctic Defender[2068:f803] At level 12 we have a score of: 0
2012-04-14 14:53:49.035 Arctic Defender[2068:f803] At level 13 we have a score of: 0
2012-04-14 14:53:49.036 Arctic Defender[2068:f803] At level 14 we have a score of: 0
2012-04-14 14:53:49.101 Arctic Defender[2068:f803] At level 15 we have a score of: 0
2012-04-14 14:53:49.102 Arctic Defender[2068:f803] At level 16 we have a score of: 0
2012-04-14 14:53:49.103 Arctic Defender[2068:f803] At level 17 we have a score of: 0
2012-04-14 14:53:49.104 Arctic Defender[2068:f803] At level 18 we have a score of: 0
2012-04-14 14:53:49.104 Arctic Defender[2068:f803] At level 19 we have a score of: 0
2012-04-14 14:53:49.105 Arctic Defender[2068:f803] At level 20 we have a score of: 0
2012-04-14 14:53:49.106 Arctic Defender[2068:f803] this is number's int value: 38 and this is thelevel - 1: 0
2012-04-14 14:53:49.111 Arctic Defender[2068:f803] At level 1 we have a score of: 0
2012-04-14 14:53:49.112 Arctic Defender[2068:f803] At level 2 we have a score of: 0
2012-04-14 14:53:49.113 Arctic Defender[2068:f803] At level 3 we have a score of: 0
2012-04-14 14:53:49.114 Arctic Defender[2068:f803] At level 4 we have a score of: 0
2012-04-14 14:53:49.114 Arctic Defender[2068:f803] At level 5 we have a score of: 0
2012-04-14 14:53:49.135 Arctic Defender[2068:f803] At level 6 we have a score of: 0
2012-04-14 14:53:49.136 Arctic Defender[2068:f803] At level 7 we have a score of: 0
2012-04-14 14:53:49.137 Arctic Defender[2068:f803] At level 8 we have a score of: 0
2012-04-14 14:53:49.138 Arctic Defender[2068:f803] At level 9 we have a score of: 0
2012-04-14 14:53:49.157 Arctic Defender[2068:f803] At level 10 we have a score of: 0
2012-04-14 14:53:49.159 Arctic Defender[2068:f803] At level 11 we have a score of: 0
2012-04-14 14:53:49.160 Arctic Defender[2068:f803] At level 12 we have a score of: 0
2012-04-14 14:53:49.160 Arctic Defender[2068:f803] At level 13 we have a score of: 0
2012-04-14 14:53:49.163 Arctic Defender[2068:f803] At level 14 we have a score of: 0
2012-04-14 14:53:49.165 Arctic Defender[2068:f803] At level 15 we have a score of: 0
2012-04-14 14:53:49.166 Arctic Defender[2068:f803] At level 16 we have a score of: 0
2012-04-14 14:53:49.167 Arctic Defender[2068:f803] At level 17 we have a score of: 0
2012-04-14 14:53:49.169 Arctic Defender[2068:f803] At level 18 we have a score of: 0
2012-04-14 14:53:49.170 Arctic Defender[2068:f803] At level 19 we have a score of: 0
2012-04-14 14:53:49.171 Arctic Defender[2068:f803] At level 20 we have a score of: 0
編集:これは私のスコアの初期化コードです:
-(id)initNewScores{
//Initalize 20 levels
for (int i = 0; i < 20; i++) {
NSNumber* numb = [[NSNumber alloc] initWithInt:0];
[scores addObject:numb];
[numb release];
}
return self;
}