Reputation: 33644
So I have the following code in my didFinishLaunchingWithOptions. The issue is that MainViewController's viewDidLoad is called twice if I uncomment the addSubView and makeKeyVisible below:
MainViewController * tabBarController = [[MainViewController alloc] init];
navigationController.delegate = self;
//[self.window addSubview:navigationController.view];
//[self.window makeKeyAndVisible];
[tabBarController release];
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeSound];
return YES;
Can anyone tell me why and how to prevent this? For me it doesn't quite make sense that when you actually alloc a UIViewController it calls the viewDidLoad.
Upvotes: 0
Views: 706
Reputation: 4623
It does make sense. From UIViewController header:
@property(nonatomic,retain) UIView *view; // The getter first invokes [self loadView] if the view hasn't been set yet. Subclasses must call super if they override the setter or getter.
- (void)viewDidLoad; // Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
Upvotes: 1