I'm making a very simple app that has lots of different quizzes. My motivation is primarily to learn Objective-C and iOS development. So I have a few views in my app, all of them have the same background which I set programmatically. I decided to make a subclass of UIViewController
which added the function setBackground
, and make all ViewControllers in my app inherit this subclass (SumsViewController
).
This worked fine, but now I'd like to take out some of the stuff that's common to each quiz and add that in to a subclass of SumsViewController
, called QuizController
. Having tried this I'm getting errors about property x not found on object of type y
.
Here's the code:
SumsViewController.h
#import <UIKit/UIKit.h>
@interface SumsViewController : UIViewController
- (void)setBackground;
@end
SumsViewController.m
#import "SumsViewController.h"
@interface SumsViewController ()
@end
@implementation SumsViewController
- (void)setBackground
{
... //Code to set Background
}
@end
QuizController.h
#import <UIKit/UIKit.h>
#import "SumsViewController.h"
@interface QuizController : SumsViewController
@property (nonatomic) NSInteger number1;
@property (nonatomic) NSInteger number2;
@property (nonatomic) NSInteger difficulty;
@property (nonatomic) NSInteger score_val;
@property (nonatomic) NSTimer* countdown;
@property (nonatomic) NSInteger time_val;
@end
QuizController.m
#import "QuizController.h"
@interface QuizController ()
@end
@implementation QuizController
@end
Now here's a controller for a quiz that inherits QuizController:
AdditionController.h
#import <UIKit/UIKit.h>
#import "QuizController.h"
@interface AdditionController : QuizController
@end
AdditionController.m
#import "AdditionController.h"
#import "ViewController.h"
@interface AdditionController ()
@property (weak, nonatomic) IBOutlet UILabel *question;
@property (weak, nonatomic) IBOutlet UILabel *timer;
@property (weak, nonatomic) IBOutlet UIButton *ans1;
@property (weak, nonatomic) IBOutlet UIButton *ans2;
@property (weak, nonatomic) IBOutlet UIButton *ans3;
@property (weak, nonatomic) IBOutlet UILabel *score;
@end
@implementation AdditionController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setBackground]; //function declared in SumsViewController WORKS FINE
self.difficulty = 20; //declared in QuizController DOES NOT WORK
// Error says property not member of object AdditionController
[self setupGame];
}
@end
I'd appreciate any help on this, I'm sure it's a simple misunderstanding but this is frustrating me.