IOS UITabBarViewController 和UINavigationController 结合使用

在AppDelegate.m  didFinishLaunchingWithOptions

UITabBarViewController *tabView=[[UITabBarViewController alloc] init];

//Tab 1
ViewController1 *VC1=[[ViewController1 alloc] init];
VC1.title=@"VC1";
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:VC1];

//Tab 2
ViewController2 *VC2=[[ViewController2 alloc] init];
VC2.title=@"VC2";
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:VC2];

//Tab 3
ViewController3 *VC3=[[ViewController3 alloc] init];
VC3.title=@"VC3";
UINavigationController *nav3=[[UINavigationController alloc]initWithRootViewController:VC3];

[tabView setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nav3,nil]];

self.window.rootViewController=tabView;
[self.window makeKeyAndVisible];

 

VC1中隐藏NavigationBar,然后显示ToolBar

[self.navigationController setNavigationBarHidden:YES animated:YES];

 

VC1 跳转到VC4

ViewController4 *VC4=[[ViewController4 alloc] init];
[self.navigationController pushViewController:VC4 animated:YES];

 

VC1 跳转到VC4  并且隐藏TabBar

方法1:

ViewController4 *VC4=[[ViewController4 alloc] init];

[VC4 setHidesBottomBarWhenPushed:YES];

[self.navigationController pushViewController:VC4 animated:YES];

 

方法2:

在VC4  m文件里面

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
   self.hidesBottomBarWhenPushed = YES;
}
return self;
}

 

关于initWithNibName 请参考

http://www.cnblogs.com/geraldzhang/archive/2011/09/21/2183970.html

 

posted on 2015-11-18 16:29  StanleyZhang  阅读(438)  评论(0编辑  收藏  举报