Why are controls (null) in awakeFromNib?
Posted
by fuzzygoat
on Stack Overflow
See other posts from Stack Overflow
or by fuzzygoat
Published on 2010-04-28T12:27:09Z
Indexed on
2010/04/28
12:43 UTC
Read the original article
Hit count: 227
This is a follow on from another question regarding why I could not set UIControls in awakeFromNib. The answer to that is that as you can see below the controls are nil in the awakeFromNib
, although they are initialised to the correct objects by the time we get to viewDidLoad
. I setup the view the same as I always do, should I be doing something different to access them here, the xib(nib) was designed and saved with the current version of Image Builder.
CODE:
@interface iPhone_TEST_AwakeFromNibViewController : UIViewController {
UILabel *myLabel;
UIImageView *myView;
}
@property(nonatomic, retain)IBOutlet UILabel *myLabel;
@property(nonatomic, retain)IBOutlet UIImageView *myView;
@end
.
@synthesize myLabel;
@synthesize myView;
-(void)awakeFromNib {
NSLog(@"awakeFromNib ...");
NSLog(@"myLabel: %@", [myLabel class]);
NSLog(@"myView : %@", [myView class]);
//[myLabel setText:@"AWAKE"];
[super awakeFromNib];
}
-(void)viewDidLoad {
NSLog(@"viewDidLoad ...");
NSLog(@"myLabel: %@", [myLabel class]);
NSLog(@"myView : %@", [myView class]);
//[myLabel setText:@"VIEW"];
[super viewDidLoad];
}
OUTPUT:
awakeFromNib ...
myLabel: (null)
myView : (null)
viewDidLoad ...
myLabel: UILabel
myLabel: UIImageView
Much appreciated ...
gary
© Stack Overflow or respective owner