views:

260

answers:

2

Here is what I do:

1) Create New UIViewController subclass , tick with NIB for interface builder

2) In the header:

@interface QuizMainViewController : UIViewController 
{
    UILabel* aLabel;
} 

@property (nonatomic, retain) IBOutlet UILabel* aLabel;

@end

3) In the .m

#import "QuizMainViewController.h"    

@implementation QuizMainViewController

@synthesize aLabel;

- (void)dealloc 
{
    [aLabel release];
    [super dealloc];
}

@end

4) Open the NIB In interface builder, drag a new UILabel into the view.

I test the program here and it runs fine.

5) right click on file's owner, connect 'aLabel' from the Outlets to the UILabel.

I run here and it crashes. Message from log:

* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aLabel.'

A: 

Try:

@interface QuizMainViewController : UIViewController 
{
    IBOutlet UILabel* aLabel;
} 

Supposedly, you no longer have to do this in Objective-C 2.0 but I've run into problems on the iPhone leaving it out.

Edit:

You could try changing

@property (nonatomic, retain) IBOutlet UILabel* aLabel;

to

@property (nonatomic, retain) IBOutlet UILabel *aLabel;

Don't think that should matter however. The compiler can usually puzzle that out.

Edit01:

In IB, make sure that he class of the view controller is set to QuizManViewController and not just UIView.

TechZen
Thanks for the suggestion, however it didn't work. Iv been going mad over this, iv tried deleting it all and starting again, but nothing works, ahhh!
Robert
See my edits for a couple of other ideas.
TechZen
+1  A: 

I have fixed the problem!

The view was being loaded from a tab bar controller, I had set the nib name to be "QuizMainViewController" but I didn't set the Class identity of the view to be "QuizMainViewController" it was stuck at the default value of "UIViewController".

When the view was loaded it thought it was an instance of UIViewController, therefore it didnt know about the aLabel property.

MORAL OF THE STORY: When using tab bar controller, set the nib name AND the class idenity for nibs that have their own view controller.

Robert