我需要创建一个带有拆分视图的应用程序,但我需要在拆分的主控方面添加一个标签栏,我已经在这个论坛中阅读了一些内容,但我无法做到正确。 我明白,当你有一个拆分视图时,你实际上处理了两个视图控制器的主人和细节,所以,据我所知,如果我需要一个标签栏在主人那边我必须从appDelegate和这个主人我内部调用主人可以将它设置为Tab Bar控制器,但要么我有一个完全的误解,要么我只是错误地实现它。
这是我在appDelegate中所做的事情,因为你可以看到我正在加载另一个VC而不是模板附带的主VC,我的第一个问题是我是否必须加载一个VC或只是一个NSObject标签栏协议?:
WTDInitialViewController *initialViewController = [[WTDInitialViewController alloc] initWithNibName:@"WTDInitialViewController" bundle:nil];
UINavigationController *initialNavigationController = [[UINavigationController alloc] initWithRootViewController:initialViewController];
WTDDetailViewController *detailViewController = [[WTDDetailViewController alloc] initWithNibName:@"WTDDetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:initialNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
现在,这就是我在所谓的VC中做的事情
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSMutableArray *vcArray = [[NSMutableArray alloc] initWithCapacity:1];
_tabBarController = [[UITabBarController alloc] init];
WTDMasterViewController *masterViewController = [[WTDMasterViewController alloc] initWithNibName:@"WTDMasterViewController_iPad" bundle:nil];
_navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
_navigationController.navigationBar.barStyle = UIBarStyleBlack;
[vcArray addObject:_navigationController];
_tabBarController.viewControllers = vcArray;
_tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;
self.tabBarController.selectedIndex = 0;
[_window addSubview:_tabBarController.view];
[_window makeKeyAndVisible];
}
return self;
这可能是一个愚蠢的问题,但我遇到了死胡同,所以,任何帮助都将不胜感激
答案 0 :(得分:0)
首先,我假设您正在为ipad创建SplitView。它最初是MasterViewController和DetailViewController。而MasterViewController是UITableview基础,现在你想要实现Tabbar基础,然后在MasterViewController的ViewWillAppear中调用它。
UIViewController *viewController1 = [[[YourTabView1 alloc] initWithNibName:@"YourTabView1" bundle:nil]autorelease];
//If you want the view support Navigation then do this
UINavigationController *tab1 = [[[UINavigationController alloc] initWithRootViewController:viewController1]autorelease];
UIViewController *viewController2 = [[[YourTabView2 alloc] initWithNibName:@"YourTabView2" bundle:nil]autorelease];
UINavigationController *tab2 = [[[UINavigationController alloc] initWithRootViewController:viewController2]autorelease];
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.viewControllers = [NSArray arrayWithObjects:tab1,tab2,nil];
[self presentModalViewController:tabbarController animated:YES];
我认为这应该有用(但我没有测试代码)。