Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically load UIViewController

Tags:

iphone

I have the following code and I want to load the UIViewController. How can I initialize and load the UIViewController.

- (void) applicationDidFinishLaunching:(UIApplication*)application
{

    CC_DIRECTOR_INIT();

    NSLog(@"applicationDidFinishLaunching");

    MainViewController *controller = [[MainViewController alloc] init]; 





}
like image 575
John Doe Avatar asked Dec 29 '22 05:12

John Doe


1 Answers

From your delegate you can do this (assuming you have IBOutlet UIWindow *window):

[window addSubview:[controller view]];
[window makeKeyAndVisible];

Once a controller is loaded, you can push others (from the UIViewController):

controller = [[MainViewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];

Here is a link to the documentation for UINavigationController.pushViewController

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/pushViewController:animated:

like image 79
codefinger Avatar answered Dec 30 '22 20:12

codefinger