2012-06-27 54 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

相關問題