ios - Objective-C:UITabBarController 黑屏

标签 ios objective-c

Bellow 我有一些代码放在 app delegate.m并用于在两个 ViewController 之间创建一个 c。标签栏的创建工作正常,但是当我选择设置标签时,没有 View ,它只是黑色。

这是代码:

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

最佳答案

你写这样设置屏幕的代码

设置 *vc2 = [[设置分配]init];

用于设置屏幕的 nib 文件在哪里,

一旦像这样尝试

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];

关于ios - Objective-C:UITabBarController 黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18802740/

相关文章:

iphone - 从手机获取 safari 历史记录

ios - 如何在键是动态的 Swift 4 中为 JSON 编写 Decodable?

ios - 如何在 iOS 7.1 中使用 NSURLSession 对 HTTP 请求和响应进行单元测试?

ios - 在哪里放置 s.static_framework = true

iOS - NSInternalInconsistencyException(表搜索)

ios - 是否可以在 iOS 中通过 FTP 写入远程文件?

c++ - "expected ' : ', ' , ', ' ; ', ' } ' or ' __attribute__ ' before ' { 结构成员函数中的' token"

ios - 如何在没有登录的情况下在 ios 中显示 facebook 新闻提要?

objective-c - 从上下文中删除托管对象而不是从一对多关系 NSSet 中删除托管对象是否安全

ios - CoreBluetooth 无法读取固件修订字符串