简体   繁体   English

Objective-C:UITabBarController黑屏

[英]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. 在下面,我有一些代码放置在app delegate.m ,并用于在两个ViewController之间创建交流。 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]; 设置* vc2 = [[Settings alloc] init];

where is the nib file for setting screen , 用于设置屏幕的笔尖文件在哪里,

Once try like this 一旦尝试这样

UITabBarController *tbc = [[UITabBarController alloc]init]; 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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