开发者

How can I build an app with multiple types of controllers?

How can I accomplish the following:

  1. When my app loads a UIView will show 4 buttons
  2. Clicking on a button will load a UITabBarController (no开发者_运维问答t a UIView with a UITabBar) that can display multiple views.

This seems challenging to me, because in order for me to use the UITabBarController I need to add this to the window's subview in my appDelegate. By doing so, my app automatically will load with the UITabbarController in the root view.


You don't need to add the UITabBarController in the application delegate, that's just the most common way to use it. You can have your initial view use a simple UIViewController, then when the button is pressed load the UITabBarController (either programmatically or from a nib), and then display it.

The following is an example of what might be in your app delegate:

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // viewController is a UIViewController loaded from MainWindow.xib with a button that calls loadTabBarController
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}

- (IBAction) loadTabBarController {
    self.tabBarController = [[[UITabBarController alloc] initWithNibName:@"MyTabBarController" bundle:nil] autorelease];
    [viewController.view removeFromSuperview];
    [window addSubview:tabBarController.view];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜