문제

I'm looking to have a system where it updates the score the user has if they get the answer right in a multiple choice question. I have an IBAction that runs when the user selects the right choice and I want it to update the score. i.e. score + 2 when answer is correct Is it something with CGFloat or NSInteger?

도움이 되었습니까?

해결책

Try something like this:

//.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;

Wherever you want to update the score, just call the scoreChanged method. Hope this helps!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top