当前位置: 代码迷 >> Iphone >> xcode4.2中Tab Bar运用解决办法
  详细解决方案

xcode4.2中Tab Bar运用解决办法

热度:302   发布时间:2016-04-25 06:42:49.0
xcode4.2中Tab Bar运用
xcode 4.2中怎样添加Tab Bar子项目呢? 
  谢谢各位先

------解决方案--------------------
我给你例子:- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self=[super initWithNibName:nil bundle:nil]) {
//tabBar1
FirstTabBar *tab1 = [[[FirstTabBar alloc] init] autorelease];
tab1.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"FirstTabBar" 
image:nil 
tag:0] autorelease];
tab1.tabBarItem.image=[UIImage imageNamed:@"icon_map.png"];


UINavigationController *tab1Nav = [[[UINavigationController alloc] init] autorelease];
[tab1Nav pushViewController:tab1 animated:NO];

// TabBar2
SecondTabBar *tab2 = [[[SecondTabBar alloc] init] autorelease];
tab2.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"SecondTabBar" 
image:nil 
tag:0] autorelease];
tab2.tabBarItem.image=[UIImage imageNamed:@"icon_search.png"];
//TabBar3
ThreeTabBar *tab3 = [[[ThreeTabBar alloc] init] autorelease];
tab3.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"ThreeTabBar" 
image:nil 
tag:0] autorelease]; 
tab3.tabBarItem.image=[UIImage imageNamed:@"icon_list.png"];
//TabBar4
FourTabBar *tab4 = [[[FourTabBar alloc] init] autorelease];
tab4.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"FourTabBar" 
image:nil 
tag:0] autorelease]; 
tab4.tabBarItem.image=[UIImage imageNamed:@"icon_twitter.png"];
// 组装TabBar
self.viewControllers = [NSArray arrayWithObjects:tab1Nav, tab2,tab3,tab4, nil];
}
return self;
}
  相关解决方案