我想创建一个用户界面,我有一个SplitView与包含TabBarController的详细信息区域。 TabBarController将为SplitView的RootViewController中选择的项目显示3种不同类型的细节。SplitViewController用户界面布局
到目前为止,我已经通过执行以下操作来使TabBar显示SPlitView;
1)创建一个新的基于SplitView的应用程序。
2)创建一个基于TabBar的应用程序
3)将FirstView和SecondView控制器的.xib,.h和.m文件从TabBar应用程序复制到SplitView应用程序中。
4)添加以下到我的应用程序委托头文件;
@class RootViewController;
@class DetailViewController;
@class FirstViewController;
@class SecondViewController;
@interface SplitViewTemplateAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UISplitViewController *splitViewController;
UITabBarController *tabBarController;
RootViewController *rootViewController;
DetailViewController *detailViewController;
FirstViewController *firstViewController;
SecondViewController *secondViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet FirstViewController *firstViewController;
@property (nonatomic, retain) IBOutlet SecondViewController *secondViewController;
5)开辟的MainWindow.xib在IB,改变了类上在DetailsView到UITabController
6)添加以下代码以我的应用程序委托模块文件;
#import "FirstViewController.h"
@synthesize window, splitViewController, rootViewController, detailViewController, tabBarController, firstViewController, secondViewController;
-(void) makeTabBarController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:splitViewController.viewControllers];
int index = 0;
for (UIViewController *controller in splitViewController.viewControllers) {
if (index == 1) {
//NSLog(@"Index is: %@", index);
//NSLog(@"Controller name is: %@", controller.title);
UINavigationController *localNavController;
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:2];
firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil];
localNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
localNavController.tabBarItem.title = @"First Tab";
[firstViewController release];
[localViewControllersArray addObject:localNavController];
[localNavController release]; // Retained by above array
secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
localNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
localNavController.tabBarItem.title = @"Second Tab";
[secondViewController release];
[localViewControllersArray addObject:localNavController];
[localNavController release]; // Retained by above array
tabBarController.viewControllers = localViewControllersArray;
[localViewControllersArray release]; // Retained thru above setter
//tabBarController.delegate = splitViewController;
[controllers replaceObjectAtIndex:index withObject:tabBarController];
}
index++;
}
splitViewController.viewControllers = controllers;
}
7)在didFinishLaunchingWithOptions方法中增加了以下内容;
[self makeTabBarController];
所以,现在我得到一个开箱SPLITVIEW的一个标签栏控制器右侧带有两个标签。选项卡用于在视图之间切换。
我现在正在努力的一些事情是;
- 用于触发Popover的按钮缺失,是否需要将它添加到每个选项卡视图?
- 如何使用TabBarController挂接RootViewController,以便显示所选项目的详细信息?
不知道我的代码发生了什么,但我可以正确地格式化它! – sparkymark75 2011-01-20 17:51:46