UItabBarController和UINavigationController结合使用

这二个东西一般都是结合使用的,简单的使用方法代码如下:

    //1.实例化一个viewController
    MoreViewController *more = [[[MoreViewController alloc] init] autorelease];

    //2.设置viewController的tabbarItem的文字和图片
    UIImage *moreImg = [UIImage imageNamed:@"settItem"];
    UITabBarItem *moreItem = [[UITabBarItem alloc] initWithTitle:@"更多" image:moreImg tag:102];
    [more setTabBarItem:moreItem];
    [moreItem release];
    
    //3.初始化一个NavigationController,并把viewController放在这个NavigationController里面
    UINavigationController *navVC1 = [[[UINavigationController alloc] initWithRootViewController:more] autorelease];
    [more.navigationItem setTitle:@"更多"];
    
    //4.初始化tabBarController并将第三步实例化的NavigationController放入tabBarController中
    UITabBarController *tabBarController = [[[UITabBarController alloc] init] autorelease];
    [tabBarController setViewControllers:[NSArray arrayWithObjects:navVC1, nil]];
    
    //5.跳转至tabBarController
    [[self navigationController] pushViewController:tabBarController animated:YES];




你可能感兴趣的:(UItabBarController和UINavigationController结合使用)