2012-05-08 68 views
3

enter image description here如何标签栏控制器添加到拆分视图控制器应用

根观点我是很新的iPad的UISplitViewController

我需要在主视图/左视图底部添加一个包含3个选项卡的选项卡栏。对于3个选项卡中的每一个,我都有不同的视图控制器。我还没有发现在基于分割视图的应用程序中使用的Tab栏的其他示例。

我在哪里插入一个标签栏控制器,以显示在根视图的底部?

如何建立连接,以便当我选择表格单元时,detailItem信息会显示在Detail View中?选项卡栏已添加到IB的根视图中。我应该以编程方式添加它吗?

+1

http://stackoverflow.com/questions/3573452/tabbarcontroller-within-the-rootviewcontroller-of-a-splitviewcontroller和http://stackoverflow.com/questions/7952214/tabbarcontroller-and-splitviewcontroller可能有帮助 – tipycalFlow

+1

哦我以为你想要整个应用程序。但基本上它是一样的想法。你可以把你的意见在tabcontroller,然后在你的主控制器中使用tabcontroller –

回答

1

你必须动态地使用UITabBarController。

在.h文件中

的UITabBarController *的TabBar;

in。M档

在appDidFinish启动创建对象到类

例如,你有

的Class1和Class2中

在appDidFinishLaunch

的Class1 * OBJ1 = [Class1的页头] initWithNibName:@“Class1”bundle:nil]; ** Class2 obj2 = [Class2 alloc] initWithNibName:@“Class2”bundle:nil]; *

//通过默认主导航控制器自带的模板代码

//现在你有一个的TabBar

的NSArray * tabViewArray = [[NSArray的页头] initWithObjects创建数组:OBJ1,OBJ2, masterNavigationController,nil];

tabBar = [[UITabBarController alloc] init];

[tabBar setViewControllers:tabViewArray];

//现在你必须编辑包含具有的TabBar splitview.viewArray repalce masterNavigataionControler

self.splitViewController.viewControllers =语句[NSArray的arrayWithObjects:TabBar,所以detailNavigationController,零]

试试这个,我希望它能帮助你。

+0

是的,这是我想要... tabbar而不是masterNavigationController – Ranga

3

在您的应用程序委托中添加tabbar控制器,然后将您的视图控制器添加到tabbar控制器并将窗口rootview控制器设置为tabbar控制器。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 
self.tabbar=[[UITabBarController alloc] init]; 

    self.vc1 = [[vc1 alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; 
    // do the same to other VCs 
    self.tabbar.viewControllers=[NSArray arrayWithObjects:vc1,vc2,vc3,vc4, nil]; 


self.window.rootViewController = self.tabbar; 

[self.window makeKeyAndVisible]; 
return YES; 

}

我希望它能帮助:-)

+0

哦,我以为你想要整个应用程序。但基本上它是一样的想法。你可以把你的意见在tabcontroller,然后使用您的主控制器中的tabcontroller –

0

所有你需要做的就是初始化uispliviewcontroller的第一个参数为视图的TabBar,而不是一个视图,或者您可以使用uisegmentedcontrol。

相关问题