1

我会接受 swift 和 objective-c 的答案,因为翻译相当容易。

我想显示一个带有初始屏幕的选项卡栏,但我不希望该初始屏幕出现在选项卡栏项目中以供选择。

我现在的设置(下图)将登陆屏幕显示为标签栏显示时第一个显示的控制器。但是,我希望隐藏该标签栏项目。用户只能选择其他三个选项卡。我该怎么做呢?

//Create and add landing view
        navigation = UINavigationController()
        landingView = WGMLandingViewController(nibName: XIBFiles.LANDINGVIEW, bundle: nil)
        navigation.pushViewController(landingView, animated: false)
        navigation.title = "Landing View"
        controllers.append(navigation)

        //Create and add library view
        navigation = UINavigationController()
        libraryView = WGMLibraryViewController(nibName: XIBFiles.LIBRARYVIEW, bundle: nil)
        navigation.pushViewController(libraryView, animated: false)
        navigation.title = "Learn More"
        controllers.append(navigation)

        //Create and add pad view
        navigation = UINavigationController()
        orderPadView = WGMOrderPadViewController(nibName: XIBFiles.ORDERPADVIEW, bundle: nil)
        navigation.pushViewController(orderPadView, animated: false)
        navigation.title = "Order Pad"
        controllers.append(navigation)

        //Create and add lookup view
        navigation = UINavigationController()
        partLookupView = WGMLookupViewController(nibName: XIBFiles.LOOKUPVIEW, bundle: nil)
        navigation.pushViewController(lookupView, animated: false)
        navigation.title = "Lookup"
        controllers.append(navigation)

        //Set up controller list
        self.setViewControllers(controllers, animated: false)
4

1 回答 1

0

Apple 现有的 API 不允许你这样做,但我们不应该太难子类化UITabBarController并让它做你想做的事。

好的..这些天我原来的答案不起作用..或者我已经老了,它从来没有起作用,我做了别的事情。*咳嗽*

所以无论如何,你必须滚动你自己的标签栏控制器。现在我们有了包含视图控制器并且您仍然可以使用UITabBar.

  1. 创建一个UIViewController(您的标签栏控制器)并在其中粘贴 aUITabBar和 a UIView
  2. 为视图创建一个出口(这是您的视图控制器所在的位置)和标签栏
  3. 配置UITabBar你想要的。
  4. 将 的 设置delegateUITabBar您的视图控制器并实现该didSelectItem方法。
  5. 创建一个方法来加载您的初始屏幕视图控制器并粘贴在您的viewDidLoad或您想要的位置。

就像是

 - (void)loadSplashScreen  {
    // load in the child view controller
    UIViewController *splashScreenController = ...;
    [self loadChildViewController:splashScreenController];

    // make sure nothing in the tab bar is selected
    self.tabBar.selectedItem = nil;
}

然后还添加代码以在选择各种选项卡时加载适当的视图控制器

 - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    // logic to figure out which view controller you want based on `item`
    // ...

    UIViewController = ...;
    [self loadChildViewController:viewController];
}

- (void)loadChildViewController:(UIViewController *)viewController {
    [self removeCurrentTabController]; // remove the existing one, if any using whatever memory management techniques you want to put in place.

    [self addChildViewController:viewController];
    [self.tabView addSubview:viewController.view];  // where self.tabView is your outlet from step 2.
}
于 2014-09-04T16:45:09.403 回答