The problem with the interface builder: when connecting IBOutlet, getting "this class is not a key value compatible with the code for the key",

That's what I'm doing:

1) Create a new subclass of UIViewController, mark with NIB for the interface designer

2) In the title:

@interface QuizMainViewController : UIViewController 
{
    UILabel* aLabel;
} 

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

@end

3) in .m

#import "QuizMainViewController.h"    

@implementation QuizMainViewController

@synthesize aLabel;

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

@end

4) Open the NIB In interface designer, drag the new UILabel to the view.

I am testing the program here and it works fine.

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

I run here and he falls. Message from the journal:

*** Application termination due to the uncaught exception "NSUnknownKeyException", reason: "[setValue: forUndefinedKey:]: this class is not a key value that is compatible with the encoding for the aLabel key. '

+3
2

!

, nib "QuizMainViewController", "QuizMainViewController", "UIViewController".

, , UIViewController, aLabel.

MORAL OF THE STORY: , .

+1

Try:

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

, Objective-C 2.0, iPhone, .

:

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

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

, . .

Edit01:

IB , QuizManViewController, UIView.

0

Source: https://habr.com/ru/post/1744136/


All Articles