在我的项目中,我主要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