跟踪分数的最简单方法是什么?

时间:2012-06-27 22:04:28

标签: ios nsinteger cgfloat

我希望有一个系统,如果他们在多项选择题中得到答案,它会更新用户所拥有的分数。我有一个IBAction,当用户选择正确的选择并且我希望它更新分数时运行。 即答案正确时得分+2 是CGFloat还是NSInteger?

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

//.h File
@property (nonatomic) NSUInteger score; //If the user can get a negative score, change "NSUInteger" to "NSInteger"
-(void)scoreChanged;

//.m File
-(void)scoreChanged{
    self.score += 2; //You can change the 2 to any number
}

//viewDidLoad
self.score = 0;

只要您想要更新分数,只需调用scoreChanged方法即可。希望这有帮助!