我正在尝试创建3个Tabbar控件,但第三个没有显示页面,任何人都知道代码有什么问题?提前完成。
FirstViewController* viewController1 = [[FirstViewController alloc]init];
MySecondViewController* viewController2 = [[MySecondViewController alloc]init];
MyThirdViewController* viewController3 = [[MyThirdViewController alloc]init];
NSArray* controllersArray = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];
tabController = [[UITabBarController alloc]init];
[tabController setViewControllers:controllersArray];
[viewController1 release];
[viewController2 release];
[viewController3 release];
答案 0 :(得分:0)
由于没有提供其他代码,我举个例子。扩展您的类,使用UITabBarController调用它。然后在你的UITabBarController子类中做类似的事情。
FirstViewController *vc1 = [[FirstViewController alloc] init];
SecondViewController *vc2 = [[SecondViewController alloc] init];
ThirdViewController *vc3 = [[ThirdViewController alloc] init];
NSArray *array = [[NSArray alloc] initWithObjects: vc1, vc2, vc3, nil];
self.controllers = array;
[vc1 release];
[vc2 release];
[vc3 release];
[array release];
然后你只需要在上面列出的三个类中设置文本和tabbarimage。
一个例子是:
[self.tabBarItem setTitle:@"FirstViewController"];
[self.tabBarItem setImage:[UIImage imageNamed:IMAGEPATH]];