我将接受迅速和客观的答案-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)
最佳答案
苹果现有的API不允许你这样做,但是我们不应该太难去子类UITabBarController
并让它做你想做的事情。
好 啊。。我原来的答案现在不行了。。或者我已经老了,再也没用了,我做了别的事情。*咳嗽*
所以无论如何,你必须滚动你自己的标签栏控制器。现在我们有了包含视图控制器,您仍然可以使用UITabBar
,这并不困难(只是时间消耗)。
创建一个UIViewController
(您的选项卡栏控制器)并在其中粘贴一个UITabBar
和一个UIView
。
为视图创建一个出口(这是视图控制器要去的地方)和选项卡栏
根据需要配置UITabBar
。
将delegate
的UITabBar
设置为视图控制器并实现didSelectItem
方法。
创建一个方法来加载您的启动屏幕视图控制器,并将其粘贴到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.
}
关于objective-c - 隐藏选项卡栏项目,但仍显示 Controller ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25670386/