I have a problem accessing a IBOutlet.
I have a NIB inside which there is a tableview, a toolbar and an UILabel (encapsulated into a view).
The controller (that is the file’s owner) is defined as:
@interface ChoixPeriodeController : UIViewController <UITableViewDelegate> {
IBOutlet UILabel* __periodeInitialeLabel;
}
@property(nonatomic, retain) UILabel* periodeInitialeLabel;
- (void) setSelectedPeriode:(Tache_TypePeriode)typePeriode;
with @synthetize periodeInitialeLabel = __periodeInitialeLabel;
In the .m file, this function is called by the parent window to init the Label :
- (void) setSelectedPeriode:(Tache_TypePeriode)typePeriode {
NSMutableString* tmpString = [NSMutableString string];
[tmpString appendFormat:some text format....];
self.periodeInitialeLabel.text = tmpString;
}
Into this function, I can see that self.periodeInitialeLabel is at nil. I can’t see why. Everything is connected into IB… Do you see what can be the problem?
The question here is the order of operations. If the text label is still nil, it’s likely it hasn’t been set up yet. Instead, you can call this method inside of the UIViewController method
viewDidLoadto handle operations like this that must do “extra configuration” that couldn’t be done in Interface Builder.There is also
awakeFromNib. They are very similar, except that awakeFromNib is called ONCE when the NIB file is unpackaged.viewDidLoadcan be called many times – for example, if there is a low memory situation (often happens on iOS4), your views will be purged viaviewDidUnload.