2011-08-30 25 views
1

我想有一个TabBar的SettingViewMain,它可以在SettingView1和SettingView2之间翻转。查看2个其他视图的简单TabBar?

我从3小时开始尝试了这个简单的工作,并尝试了几乎所有我找到的教程,但我没有得到它的工作。

当我尝试以编程方式添加TabBar时,我可以在这两个视图之间切换,但在此视图本身中TabBar未显示,不知道原因。当我添加一个TabBarController时,根本没有显示。

所以,simlpy:我如何在MasterView上添加一个TabBar(不是AppDelegate-Window或类似的东西),并让TabBar在View1和View2之间切换?

回答

2

你可以使用它的alloc和init方法实例化一个UITabBarController。 实例化其他ViewControllers并将它们添加到数组。 完成后,将其视图添加到您的'MasterView'中。

代码:

UITabBarController *tab = [[UITabBarController alloc] init]; 
UIViewController *controller1 = [[UIViewController alloc] init]; 
UIViewController *controller2 = [[UIViewController alloc] init]; 

NSArray *controllers = [[NSArray alloc] initWithObjects:controller1, controller2, nil]; 
[tab setViewControllers:controllers]; 

[[self view] addSubview:[tab view]]; 

或者密切的东西比这一点。

祝你好运!

Bryan