Being new to Cocoa, I'm having a few issues with Interface Builder
, UIViewController
and friends.
I have a UIViewController
subclass with a UIView
defined in a xib, and with the controller's view outlet connected to the view. The xib's "file's owner" is set as myViewcontroller subclass.
In this one instance, the following code to load the controller/view (from the main view controller) doesn't work as expected:
if ( self.myViewController == nil )
{
self.myViewController = [[MyViewController alloc]
initWithNibName:@"MyViewController" bundle:nil];
}
[self.navigationController
pushViewController:self.myViewController animated:YES];
In MyViewController's methods, I have placed breakpoints and log messages to see what is going on:
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
NSLog(@"initWithNibName
");
}
return self;
}
-(void)viewDidLoad {
[super viewDidLoad];
NSLog(@"viewDidLoad
");
}
Expected result
Both -initWithNibName
and -viewDidLoad
methods are called, and myViewController's view is displayed.
Observed result
Only -initWithNibName
is called, the view is not displayed.
Have I missed something? Can anyone recommend anything to check? (Particularly in the wondrously opaque Interface Builder tool).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…