如何将UITabBarController添加到窗口

时间:2011-04-19 20:45:01

标签: uiviewcontroller uitabbarcontroller

嗨,我有一个窗口和一个标签栏。如何将所有视图控制器添加到选项卡栏和窗口。我的代码在这里

UITabBarController *tab = [[UITabBarController alloc] init];

UIViewController *first = [[UIViewController alloc] init];
UIViewController *second = [[UIViewController alloc] init];
UIViewController *third = [[UIViewController alloc] init];

//HOW can i add these view controllers to tabbar and hwo to add tabbar to window...


[self.window makeKeyandVisible];

请帮忙..谢谢

1 个答案:

答案 0 :(得分:0)

我是新来的,但我认为这会奏效。那里也有很多东西,所以你可能想看看它们。如果可以的话,我会尽力找到一个,但我认为这就足够了。

UITabBarController *tab = [[UITabBarController alloc] init];

UIViewController *first = [[UIViewController alloc] init];
UIViewController *second = [[UIViewController alloc] init];
UIViewController *third = [[UIViewController alloc] init];

NSArray *tt = [[NSArray alloc] initWithObjects:first, second, third, nil];

tab.viewControllers = [[NSArray alloc] initWithArray:tt]; 

[self.window addSubview:[tab view]];
[self.window makeKeyAndVisible];