UITabBarController和UINavigationController混用

1.新建一个single view工程:

      

2.在AppDelegate.m中

    MyUIViewController *vc1 = [[MyUIViewController alloc] init];
    vc1.title = @"vc1";
    vc1.view.backgroundColor = [UIColor grayColor];
    UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
    [vc1 release];
    
    UIViewController *vc2 = [[UIViewController alloc] init];
    vc2.title = @"vc2";
    vc2.view.backgroundColor = [UIColor redColor];
    UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
    [vc2 release];
    
    UIViewController *vc3 = [[UIViewController alloc] init];
    vc3.title = @"vc3";
    vc3.view.backgroundColor = [UIColor purpleColor];
    UINavigationController *nc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
    [vc3 release];
    
    UIViewController *vc4 = [[UIViewController alloc] init];
    vc4.title = @"vc4";
    vc4.view.backgroundColor = [UIColor greenColor];
    UINavigationController *nc4 = [[UINavigationController alloc] initWithRootViewController:vc4];
    [vc4 release];
    
    UITabBarController *tbc = [[UITabBarController alloc] init];
    tbc.viewControllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nc4, nil];
    self.window.rootViewController = tbc;
    [tbc release];
    
    [nc1 release];
    [nc2 release];
    [nc3 release];
    [nc4 release];
效果如图



在MyViewController中添加

- (void)btnClick
{
    SecondViewController *svc = [[SecondViewController alloc] init];
    svc.view.backgroundColor = [UIColor whiteColor];
    svc.title = @"second";
    [self.navigationController pushViewController:svc animated:YES];
    [svc release];
}

效果如图



点next按钮,效果如图




如果希望底部的tabbar在跳转至后消失,可以在

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

之前添加

self.hidesBottomBarWhenPushed = YES;

这样跳转至后就没有底部的tabbar了,但是点左上的vc1按钮返回到第一个界面的时候发现底部的tabbar仍然不在,所以需要添加如下代码,使其返回的时候会弹出tabbar

- (void) viewDidDisappear:(BOOL)animated
{
    self.hidesBottomBarWhenPushed = NO;
}



  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值