i have a subclass of NSViewController that loads its view from a nib (with initWithNibName:bundle: and it is the file's owner of that nib).
I need to do some initialization after the nib is loaded and i want my code to be the most compatible :
So my questions are :
- (void)initAfterNibLoaded { ... } - (void)viewDidLoad { // Code for ios [self initAfterNibLoaded]; } - (void)awakeFromNib { // Code for osx // Not sure if necessary [super awakeFromNib]; [self initAfterNibLoaded]; }
If answer 1 is NO, is this a good solution ? :
- (void)viewDidLoad {
// Initialize after nib loaded
}
#ifndef TARGET_OS_IPHONE
- (void)loadView {
// Call parent method
[super loadView];
// Simulate viewDidLoad method
[self viewDidLoad];
}
#endif
Thank you
Here is what I found:
Yes, awakeFromNib
: is called also on the file's owner of the nib in Lion (and normally it's the same for the new Mountain Lion).
Starting on OSX 10.6, there is a category on NSObject
that adds awakeFromNib
, so it's safe to call [super awakeFromNib]
from any subclass. For OSX before 10.6, we can use instancesRespondToSelector
: to know if the parent class implements awakeFromNib
, the NSView
or NSObject
subclass must not call [super awakeFromNib]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With