Bellow我有一些代码放在app delegate.m
中,用于在两个ViewController之间创建一个c。标签栏的创建工作正常,但是当我选择设置选项卡时,没有视图它只是黑色。
以下是代码:
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;
}
答案 0 :(得分:2)
您可以像这样编写设置屏幕的代码
设置* vc2 = [[设置分配]初始化];
用于设置屏幕的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];
答案 1 :(得分:1)
尝试:
- (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;
}