开发者

How to use the 'setMyViewController' in iPhone'?

I want to ask a question about the iPhone application. In my program, there are several controller class. However, I dont' know how to handle them and switch the control right between different view controller classes. I read some code from the apple website. Can anyone explain to me? Thank you very much.

// I create a view controller called 'MyViewController' 
- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    NSLog(@"applicationDidFinishLaunching");

    MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]; // what meaning of this statement
    [self setMyViewController:aViewController]; // can I set i开发者_开发问答n other class
    [aViewController release];

    UIView *controllersView = [myViewController view]; // what is it use?
    [window addSubview:controllersView];

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}


// what meaning of this statement
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]; 

This block will load your main view controller from the .xib file. Do you know about Interface Builder, you can set the View of the ViewController in the MyViewController.xib and then load it using this line

[self setMyViewController:aViewController]; // can I set in other class

Theoretically, you can set a ViewController in anywhere you have viewControlelr as a property. However, the code here means that you set the aViewController as your root view controller in the program, the first view controller you will see when you open the program.

   UIView *controllersView = [myViewController view]; // what is it use?
    [window addSubview:controllersView];

These 2 lines will make the view visible and can be seen by the user. you add the subview of your root view controller into the main window, and then show it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜