Mauricio Galindo
Mauricio Galindo

Reputation: 658

UIViewController IBOutlets are nil

I have an UIViewController class with two labels and a UIImageView set as IBOutlets, and I have this outlets connected in my xib, I have double checked they are connected properly, however when I check the their value in the debugger they are 0x0 so I cant change them programatically. Any ideas on what I might be doing wrong.

Heres the header file of my code:

#import <UIKit/UIKit.h>


@interface PlateDetailViewController : UIViewController {

     IBOutlet UIImageView *image;
     IBOutlet UILabel *price;
     IBOutlet UILabel *description;

}

@property (nonatomic, retain)IBOutlet UIImageView *image;

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

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


@end

Upvotes: 8

Views: 5515

Answers (1)

Noah Witherspoon
Noah Witherspoon

Reputation: 57139

Your outlets won't get set until the view controller's view is actually instantiated, which in your case is probably happening shortly after initWithNibName:bundle:—at which point they'll still be nil. Any setup you do that involves those outlets should be happening in your view controller's -viewDidLoad method.

Upvotes: 23

Related Questions