2012-06-27 65 views
-3

我正在寻找一个系统,它可以更新用户拥有的分数,如果他们在多项选择题中得到答案的话。我有一个IBAction,当用户选择正确的选择并且我希望它更新分数时运行。 即答案正确时得分+2 它是CGFloat还是NSInteger?跟踪分数的最简单方法是什么?

回答

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方法。希望这可以帮助!

+0

谢谢,这个效果很好 – user1282180

相关问题