Reputation: 33050
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
Everything works fine. The code above is standard written by compiler. Nothing strange. I put breakpoints there in my viewControllers just to see how things go.
Sometimes the function is called. Sometimes it's not. ' In all cases things work fine. But what would be the circumstances where that function is not called?
Yes, I am using XIB for all those viewControllers.
I notice that viewControllers directly under the navigationViewController is the one where initWithNibName doesn't break. I wonder why.
Upvotes: 2
Views: 352
Reputation: 46533
When your NSViewController is defined in a xib file (usually as an IBOutlet), initWithNibName:bundle: is not called, rather initWithCoder: gets called. This is the case when you use Interface Builder to set your NSViewController as part of UITabBarController(for UIViewController) or UINavigationController, and almost always when using Storyboards.
Or you can try this one also:
myViewController *objMyViewController = [[MyViewController alloc] initWithNibName:@"WebViewController_iPhone" bundle:nil];
objMyViewController.managedObjectContext = self.managedObjectContext;
navController = [[UINavigationController alloc] initWithRootViewController:objMyViewController];
[self.window setRootViewController:navController];
[window makeKeyAndVisible];
Upvotes: 3