I’m making a view based quiz app for the iPhone where the player is going randomly between three different views when answering the questions. They get +1 when answering correct and -1 when tapping the wrong answer. But after answering the question, when you go to the new random view, I need the UILabel to show the score from the previous view. How do I do that?
Here is my code:
ViewController.h
@interface ViewController : UIViewController {
IBOutlet UILabel *labelQuestion;
IBOutlet UILabel *labelAnswer1;
IBOutlet UILabel *labelAnswer2;
IBOutlet UILabel *labelAnswer3;
IBOutlet UILabel *labelScore;
int score;
}
@property (nonatomic, retain) IBOutlet UILabel *labelScore;
@property (nonatomic) int score;
ViewController.m
@synthesize labelScore;
@synthesize score;
-(IBAction)CorrectAnswer; {
score = score +1;
labelScore.text = [NSString stringWithFormat:@"%i", score];
}
-(IBAction)WrongAnswer; {
score = score -1;
labelScore.text = [NSString stringWithFormat:@"%i", score];
}
Make the variable score global i.e. define this in your
AppDelegateand you can access it throughout your application.