I created a new Xcode project with a view-based application template. In the .m view controller, I rewrote this:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
NSLog(@"initWithNibName...");
}
return self;
}
- (id)init {
NSLog(@"initWithNibName...");
return [super init];
}
However, I never get this NSLog. This is also my experience from other projects. This method is never called. Not even from NSObject.
The view controller is created inside the XIB file. Is it possible that the Nib Loading System instantiates this class without any initialization?
Why? What is the alternative to -loadView and -viewDidLoad?
Another great reason to stay away from XIB files?
source
share