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.'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With