UITabBarController不会显示

时间:2015-03-15 19:02:41

标签: ios objective-c xcode6 uitabbarcontroller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.main_tabs = [[UITabBarController alloc] init];
    self.viewController1 = [[ViewController alloc] initWithNibName:nil bundle:NULL];
    self.viewController1.title = @"Home";
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:self.viewController1];

    self.viewController2 = [[ViewController2 alloc] initWithNibName:nil bundle:NULL];
    self.viewController2.title = @"About";
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:self.viewController2];


    self.tabs_array = [[NSArray alloc] initWithObjects:nav1,nav2, nil];
    self.main_tabs.viewControllers = self.tabs_array;
    [self.window addSubview:self.main_tabs.view];
    return YES;
}

这是我的appDelegate文件中的代码。我已经以编程方式添加了一个UITabBarController但它根本不会显示。没有出现任何错误或警告,也没有记录任何内容。有任何想法吗?提前谢谢......

1 个答案:

答案 0 :(得分:0)

将您的代码更改为:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UITabBarController *main_tabs = [[UITabBarController alloc] init];
    self.viewController1 = [[ViewController alloc] initWithNibName:nil bundle:NULL];
    self.viewController1.title = @"Home";
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:self.viewController1];

    self.viewController2 = [[ViewController2 alloc] initWithNibName:nil bundle:NULL];
    self.viewController2.title = @"About";
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:self.viewController2];

    main_tabs.viewControllers = @[ nav1, nav2 ];
    self.window.rootViewController = main_tabs;
    return YES;
}