To manage its relationships and responsibilities, QuizAppDelegate needs five instance variables and two methods. In this section, you will declare these in the QuizAppDelegate header file, QuizAppDelegate.h.
Here are the five instance variables QuizAppDelegate needs:
In the project navigator, select QuizAppDelegate.h. Inside the curly braces, add the following declarations for the five instance variables. (Notice the bold type? In this book, code that you need to add is always bold; the code that’s not bold is there to tell you where to type in the new stuff.)
@interface QuizAppDelegate : NSObject <UIApplicationDelegate> { int currentQuestionIndex; // The model objects NSMutableArray *questions; NSMutableArray *answers; // The view objects - don't worry about this IBOutlet macro, // we'll talk about it shortly IBOutlet UILabel *questionField; IBOutlet UILabel *answerField; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end
(Scary syntax? Feelings of dismay? Don’t panic – you will learn more about the Objective-C language in the next chapter. For now, just keep going.)
Each of the buttons needs to trigger a method in the QuizAppDelegate. A method is a lot like a function – a list of instructions to be executed. Declare two methods in QuizAppDelegate.h after the line that starts with @property. (We will explain @property in Chapter 3; you can ignore it for now.)
@interface QuizAppDelegate : NSObject <UIApplicationDelegate> { int currentQuestionIndex; // The model objects NSMutableArray *questions; NSMutableArray *answers; // The view objects IBOutlet UILabel *questionField; IBOutlet UILabel *answerField; } @property (nonatomic, retain) IBOutlet UIWindow *window; - (IBAction)showQuestion:(id)sender; - (IBAction)showAnswer:(id)sender; @end
Save QuizAppDelegate.h.
What do IBOutlet and IBAction do in the declarations you just entered? They allow you to connect your controller and view objects in the XIB file.
3.138.34.226