UITabBarController与UINavigationController配合使用

- (IBAction)enterBarDemo:(id)sender {

    /**

     首先添加好导航控制器

     **/

    NSMutableArray * items = [[NSMutableArray alloc]init];

    

    //每个标签下的第一个controller

    TestOneController* testOne = [[TestOneController alloc]init];

    TestTwoController *testTwo = [[TestTwoController alloc]init];

    TestThirdViewController* testthird = [[TestThirdViewController alloc]init];


    //每个标签对应的导航

    UINavigationController* nav1 = [[UINavigationController alloc] initWithRootViewController:testOne] ;//每个导航中加入了其对应的第一个controller

    UINavigationController* nav2 = [[UINavigationController alloc] initWithRootViewController:testTwo];//每个导航中加入了其对应的第一个controller

    UINavigationController* nav3 = [[UINavigationController alloc] initWithRootViewController:testthird];//每个导航中加入了其对应的第一个controller


    //将导航添加到数组中

    [items addObject:nav1];

    [items addObject:nav2];

    [items addObject:nav3];


    /**

     其次添加标签控制器

     **/

    

    //新建TabBar,并且将数组中的导航根加入其中。

    TabBarViewController* tabBar = [[TabBarViewController alloc]init];

    [tabBar setTitle:@"TabBarController"];

    [tabBar setViewControllers:items];

    

    [self presentModalViewController:tabBar animated:NO];

    

}

你可能感兴趣的:(ios,C++,标签)