1

这个问题类似于这个问题,但它是在 Xcode 5 不存在时创建的。而这个问题仍然没有答案。关于如何删除情节提要也有类似的问题,但它们是关于导航控制器,而不是标签栏控制器。

我的行动顺序:

  1. 创建选项卡式应用程序

  2. 删除所有情节提要文件

  3. 从 .plist 中删除情节提要

  4. 创建 UITabBarController 子类并编辑 xib

  5. 更改应用委托:

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

    return YES;
}

结果是带有灰色位置而不是标签栏的黑屏。

错误在哪里?

4

1 回答 1

2

您会看到黑屏,因为您的标签栏是空的,因此您必须将 ViewController 添加到您的 TabController。

像这样修改你的 AppDelegate:

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

    FirstViewController* firstView = [[FirstViewController alloc]initWithNibName:nil bundle:nil];
    firstView.title = @"FIRST"; //THIS WILL BE THE TITLE OF YOUR FIRST TAB

    SecondViewController* secondView = [[SecondViewController alloc]initWithNibName:nil bundle:nil];
    secondView.title = @"SECOND";//THIS WILL BE THE TITLE OF YOUR SECOND TAB

    //ADD VIEW CONTROLLER TO YOUR TAB CONTROLLER
    self.tabBarController.viewControllers = @[firstView,secondView];

    [self.window makeKeyAndVisible];
    return YES;
}

概括:

  1. 向您的 Xcode 项目添加两个或多个新 ViewController(例如 FirstViewController、SecondViewController)。
  2. 通过将此 ViewControllers 添加到您的标签栏控制器来修改您的应用程序委托。
于 2015-12-03T17:58:56.067 回答