Connect a UILabel in Interface Builder and XCode?

Assuming your view is called ExampleView. Click on the file owner and then press ⌘+4. This will highlight the identity box. Make sure that the class name is the same as the name of your class.

Save and close Interface Builder and then go into Xcode and verify:

// ExampleViewController.h
#import <UIKit/UIKit.h>

@class ExampleViewController;
@interface ExampleViewController : UIViewController {

    IBOutlet UILabel *label;
}

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

@end

In your .m file:

// ExampleViewController.m
#import "ExampleViewController.h"

@implementation ExampleViewController

@synthesize label;

Then save the xcode files and open up your ExampleView. Drag a label onto the view. You are not supposed to connect that label to the Files owner.

INSTEAD YOU CLICK THE FILEOWNER. HIT ⌘+2 this will open the connections box. then you will see your outlet. Click and connect that to your label.


Make sure your property line looks like this:

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

Leave (or set) the type of the label as UILabel in Interface Builder. If that doesn't work, try File -> Reload All Class Files in Interface Builder. Your code looks good, but CardNameLabel should start with a lower-case 'c'.


Try this: click on the File's Owner icon to select it, and go to the Inspector's Identity tab (the 4th tab) and check the value of the Class setting. My guess is that's it's currently set to UIViewController.

Since the class that has the IBOutlet you declared is (or should be) a subclass of UIViewController, you'll need to change the class name to the name of your subclass (e.g., MyController, or whatever it's currently named).