如果二级控制器也是包含tabbar

来源:互联网 发布:松潘这两天网络怎么了 编辑:程序博客网 时间:2024/05/29 05:06

如果二级控制器也是包含tabbar 


#import "AppDelegate.h"


#import "FirstVC.h"

#import "SecondVC.h"


@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    self.window = [[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];

    [self.windowmakeKeyAndVisible];

    

   FirstVC *vc1 = [[FirstVCalloc] init];

    vc1.view.backgroundColor = [UIColormagentaColor];

    UINavigationController *nav1 = [[UINavigationControlleralloc] initWithRootViewController:vc1];

    

   SecondVC *vc2 = [[SecondVCalloc] init];

    vc2.view.backgroundColor = [UIColorcyanColor];

    UINavigationController *nav2 = [[UINavigationControlleralloc] initWithRootViewController:vc2];

    

    UITabBarController *tab = [[UITabBarControlleralloc] init];

    self.window.rootViewController = tab;

    tab.viewControllers =@[nav1, nav2];

    

    nav1.tabBarItem.title =@"一级1";

    nav2.tabBarItem.title =@"一级2";

    

    return YES;

}

===============================================================================================================

#import "FirstVC.h"


#import "ThirdVC.h"


@interface FirstVC ()


@end


@implementation FirstVC


- (void)viewDidLoad {

    [superviewDidLoad];

    UIButton *nextPage = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [nextPage setTitle:@"next"forState:UIControlStateNormal];

    [self.viewaddSubview:nextPage];

    nextPage.frame =CGRectMake(0,0, 50, 80);

    nextPage.center =self.view.center;

    

    [nextPage addTarget:selfaction:@selector(next)forControlEvents:UIControlEventTouchUpInside];

}


- (void)next {

    

    //注意这里再创建新的控制器的时候不用再包一层nav

   ThirdVC *vc11 = [[ThirdVCalloc] init];

    vc11.view.backgroundColor = [UIColoryellowColor];

    

    UIViewController *vc12 = [[UIViewControlleralloc] init];

    vc12.view.backgroundColor = [UIColorlightGrayColor];

    

    UITabBarController *tab1 = [[UITabBarControlleralloc] init];

    tab1.viewControllers =@[vc11, vc12];

    

    vc11.tabBarItem.title =@"二级1";

    vc12.tabBarItem.title =@"二级2";

    

    self.hidesBottomBarWhenPushed =YES;

    [self.navigationControllerpushViewController:tab1 animated:YES];

    NSLog(@"FirstVC %@",self.navigationController);

    self.hidesBottomBarWhenPushed =NO;

}


===============================================================================================================

#import "ThirdVC.h"


@interface ThirdVC ()


@end


@implementation ThirdVC


- (void)viewDidLoad {

    [superviewDidLoad];

    UIButton *NEXT = [UIButtonbuttonWithType:UIButtonTypeSystem];

    [NEXT setTitle:@"NEXT"forState:UIControlStateNormal];

    [self.viewaddSubview:NEXT];

    NEXT.frame =CGRectMake(0,0, 50, 50);

    NEXT.center = self.view.center;

    

    [NEXT addTarget:selfaction:@selector(nEXT)forControlEvents:UIControlEventTouchUpInside];

}


- (void)nEXT {

    

    UIViewController *vc111 = [[UIViewControlleralloc] init];

    vc111.view.backgroundColor = [UIColorredColor];

    

    //注意这里包裹这个控制器的tabVC和前一个页面属于同一级,所以要隐藏第一个tabbar,这句代码必须写

    self.tabBarController.hidesBottomBarWhenPushed =YES;

    //注意这里隐藏的是第二个tabbar

    self.hidesBottomBarWhenPushed =YES;

    //注意这里self.navigationController就是推过来tabVCnav

    [self.navigationControllerpushViewController:vc111 animated:YES];

    NSLog(@"ThirdVC %@",self.navigationController);

    self.hidesBottomBarWhenPushed =NO;

}



0 0
原创粉丝点击