【发布时间】:2011-01-20 17:49:09
【问题描述】:
我正在尝试创建一个 UI,其中我有一个包含 TabBarController 的详细信息区域的 SplitView。 TabBarController 将为在 SplitView 的 RootViewController 中选择的项目显示 3 种不同类型的详细信息。
到目前为止,我已经通过执行以下操作使 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) 在 IB 中打开 MainWindow.xib 并将 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 的按钮,是否需要将其添加到每个选项卡视图中?
- 如何将 RootViewController 与 TabBarController 挂钩,以便显示所选项目的详细信息?
【问题讨论】:
-
不知道我的代码发生了什么,但我可以正确格式化它!
-
hm,似乎列表标记和代码标记存在问题。我改变了它,使代码看起来很好
-
谢谢,你有机会回答我的问题吗? ;)
-
我的 iPad 技能非常有限。 :S
-
我添加了 [cocoa-touch] 标签以引起更多关注。但是你应该想出一个更好的标题。
标签: objective-c cocoa-touch ipad uitabbarcontroller uisplitviewcontroller