【问题标题】:How to programmatically add a UITabBarController & UINavigationController in AppDelegate?如何以编程方式在 AppDelegate 中添加 UITabBarController 和 UINavigationController?
【发布时间】:2014-11-25 18:32:01
【问题描述】:

如何在应用委托中以编程方式添加UINavigationControllerUITabBarController

【问题讨论】:

    标签: ios objective-c uinavigationcontroller uitabbarcontroller appdelegate


    【解决方案1】:

    不要忘记在 AppDelegate.h 文件中添加:

    @property (strong, nonatomic) UITabBarController *tabBarController;
    

    下面是 AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
    
        self.tabBarController = [[UITabBarController alloc] init];
    
        ViewController1 *VC1 = [[ViewController1 alloc] init];
        VC1.title = @"Tab Title Here";
        UINavigationController *VC1Navigation = [[UINavigationController alloc]
                                                    initWithRootViewController:VC1];
    
        ViewController2 *VC2 = [[ViewController2 alloc] init];
        VC2.title = @"Tab Title Here";
        UINavigationController *VC2Navigation = [[UINavigationController alloc]
                                                    initWithRootViewController:VC2];
    
        ViewController3 *VC3 = [[ViewController3 alloc] init];
        homeView.title = @"Tab Title Here";
        UINavigationController* VC3Navigation = [[UINavigationController alloc]
                                                 initWithRootViewController:VC3];
    
        NSArray* controllers = [NSArray arrayWithObjects:VC1Navigation, VC2Navigation, VC3Navigation, nil];
        self.tabBarController.viewControllers = controllers;
    
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 2015-03-15
      • 2015-01-07
      相关资源
      最近更新 更多