开发者

iphone sdk uitabbarcontroller does not work

开发者 https://www.devze.com 2023-02-01 04:31 出处:网络
I\'m trying to create 3 Tabbar control but the third one does not display the page, anyone know what\'s wrong with the code? Thanx in advance.

I'm trying to create 3 Tabbar control but the third one does not display the page, anyone know what's wrong with the code? Thanx in advance.

        FirstViewController* viewController1 = [[FirstViewController alloc]init]; 
 MySecondViewController* viewController2 = [[MySecondViewController alloc]init];
 MyThirdViewController* viewController3 = [[MyThirdViewController alloc]init];


 NSArray* controllersArray = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];              
 tabCon开发者_JAVA百科troller = [[UITabBarController alloc]init];
 [tabController setViewControllers:controllersArray]; 

 [viewController1 release];
 [viewController2 release];
 [viewController3 release];


Since no other code is provided, I give you an example. Extend your class, call it whatever you want with UITabBarController. Then in your UITabBarController subclass do something like this.

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];

Then you just have to set up the text and tabbarimage in the three classes listed above.

An example would be:

[self.tabBarItem setTitle:@"FirstViewController"];
[self.tabBarItem setImage:[UIImage imageNamed:IMAGEPATH]];
0

精彩评论

暂无评论...
验证码 换一张
取 消