Frage

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?

War es hilfreich?

Lösung

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!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top