我正在设计一个应用程序,并希望使用UITabBarController来管理我的视图控制器。但是我有超过5个视图控制器要显示,但我不喜欢苹果默认的“moreNavigationController”设计用于显示其他viewControllers。我宁愿让第五个选项卡像一个开关更改其他选项卡和链接视图控制器。我认为这不是苹果公司首选的标签栏控制器。
我找到了一种方法来做到这一点,它似乎没有错误地正常工作。但是想知道这是不是一个好主意。我没有看到使用这种方法的其他例子。任何想法将不胜感激。谢谢。这是精简/伪代码: -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController* mainTabController = [[UITabBarController alloc] init];
// Make the appDelegate the TabBarController delegate to process method below
mainTabController.delegate = self;
// Add my custom View Controllers as first four objects
// Add a blank View Controller as the fifth object which will act as a switch
self.window.rootViewController = mainTabController;
[self.window addSubview:mainTabController.view];
[self.window makeKeyAndVisible];
return YES;
}
// TabBarController delegate method
// Called whenever a tab is selected
-(BOOL) tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
// Test for the 5th View Controller Tab selection
if (viewController == matches the fifth VC)
{
// Add a new set of VC to an array again with the fifth being a blank
// which is never selected and acts as a switch
[tabBarController setViewControllers:array animated:YES];
// return No to ensure the 5th tab VC is not shown
return NO;
}
// Again Test for the new 5th VC added above
if (viewController == matches the new fifth VC)
{
// Same setup as above but selecting the original view controllers array
[tabBarController setViewControllers:array animated:YES];
return NO;
}
return YES;
}
答案 0 :(得分:0)
我发现使用Apple的API不是首选用途的东西总是一个坏主意,这是多重原因:
您需要检查您的代码,了解Apple所做的每一次更新,看它是否没有破坏它。 你现在可以找到一种方法,但只要你想做更多的事情,你就会遇到问题。
我的建议是,创建你自己的TabBarController,它并不难做,你可以让它适合你的想法。