UITabBarController 不会显示

UITabBarController wont show

- (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,但它根本不会显示。没有显示任何错误或警告,也没有记录任何内容。有任何想法吗?提前致谢...

将您的代码更改为:

- (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;
}