NSMutableArray值未更改

时间:2012-11-26 01:54:59

标签: ios delegates nsmutablearray nsnumber

在我的项目中,我从主GameClass尝试将数据保存到控件类NSMutableArray中的成就ViewController(这是GameClass的委托),但数组的值似乎没有改变。这是我的代码:

在GameClass.m中

NSLog(@"test %i",[delegate getAchievement:3]);
[delegate setAchievement:3];
NSLog(@"test %i",[delegate getAchievement:3]);

在ViewController.m中

-(void)setAchievement: (int)number{

     [achievements replaceObjectAtIndex: number withObject: [[NSNumber alloc] initWithInt:1]];
     NSLog(@"setachievement was called");

     [self saveData];
}

-(int)getAchievement: (int)number{

    return [[achievements objectAtIndex: number] intValue];
}

我得到的是:

 2012-11-25 20:47:14.754 Stickman Parkour 2[25109:c07] test 0
 2012-11-25 20:47:14.755 Stickman Parkour 2[25109:c07] setachievement was called
 2012-11-25 20:47:14.755 Stickman Parkour 2[25109:c07] test 0

1 个答案:

答案 0 :(得分:1)

任何一个代表是零或成就是零。对nil的调用返回零/零。 (但是,既然出现了“设定成就被召唤”,那表明代表是好的,成就就是零。)