Reputation: 45
I have been a big fan of this site for a long time, but this is my first posted question.
I have read every post similar to the topic (I think), however they all are using NIB files. I have NO nib files anywhere in my project.
It's a simple project with one view (so that mean one delegate class, one uiviewcontroller class, and one uiview class), and my view displays fine, except the viewDidLoad method is never called.
main.m looks like this:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"MyAppDelegate");
[pool release];
return retVal;
}
MyAppDelegate.m looks like this:
-(void)applicationDidFinishLaunching:(UIApplication *)application{
UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = localWindow;
[localWindow release];
MainViewController *viewController = [[MainViewController alloc] init];
//Option 1
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
////Option 2
//navigationController = [[UINavigationController alloc] init];
//navigationController.viewControllers = [NSArray arrayWithObject:viewController];
////Option 3
//navigationController = [[UINavigationController alloc] init];
//[navigationController pushViewController:viewController animated:NO];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
[viewController release];
}
in MainViewController.m
- (id)init {
self = [super init];
if (self) {
self.title = @"Root";
MainView *myView = [[MainView alloc] init];
[myView initWithParentViewController:self];
self.view = myView;
[myView release];
}
return self;
}
Finally, in "MainViewController.m", this is never fired (but the view is displayed):
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"VIEW DID LOAD");
}
Upvotes: 3
Views: 2818
Reputation: 16827
If you have no nib file you should be implementing the loadView method. See "Creating the View Programmatically" in the Custom View Controllers section of the View Controller Programming Guide. If you don't implement this method viewDidLoad will not be called.
Upvotes: 5