简体   繁体   中英

Objective-C: UITabBarController Black Screen

Bellow i have some code that is place in the app delegate.m and is used to create ac between two ViewControllers. The creation of the tab bar works fine but when i select the setting tab there is no view it is just black.

Here is the code:

import "ViewController.h"
#import "Settings.h"

@implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];

        UITabBarController *tbc = [[UITabBarController alloc]init];

        ViewController *vc1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
        Settings *vc2 = [[Settings alloc]init];

        [vc1.tabBarItem setTitle:@"Browse"];
        [vc2.tabBarItem setTitle:@"Settings"];

        [tbc setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
        [self.window setRootViewController:tbc];

        return YES;
    }

You write the code for setting screen like this

Settings *vc2 = [[Settings alloc]init];

where is the nib file for setting screen ,

Once try like this

UITabBarController *tbc = [[UITabBarController alloc]init];

ViewController *vc1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
Settings *vc2 = [[Settings alloc]initWithNibName:@"Settings" bundle:nil];

[vc1.tabBarItem setTitle:@"Browse"];
[vc2.tabBarItem setTitle:@"Settings"];

[tbc setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
[self.window setRootViewController:tbc];
[self.window makeKeyAndVisible];

try with:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UITabBarController *tbc = [[UITabBarController alloc]init];

    ViewController *vc1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    Settings *vc2 = [[Settings alloc]init];

    [vc1.tabBarItem setTitle:@"Browse"];
    [vc2.tabBarItem setTitle:@"Settings"];

    [tbc setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
    [self.window setRootViewController:tbc];
    [self.window makeKeyAndVisible];

    return YES;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM