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/