0

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.

James
  • 3,957
  • 4
  • 37
  • 82
  • 1
    I also noticed your `NSTimer` is not defined as `strong` which is almost definitely a mistake. It should probably be `@property (nonatomic, strong) NSTimer* countdown;` – Dima Feb 10 '14 at 19:37
  • Yeah that was a typo when I copied it over, it is defined as `strong` in my code. – James Feb 10 '14 at 19:38

1 Answers1

2

Try cleaning you project and re building files ( Command + Shift + K ). I'm suggesting that because I just copied your code in a sample project, and it works fine on my computer.

Sepehrom
  • 1,335
  • 2
  • 16
  • 33