如何将基于导航的iPhone应用程序转换为基于TabBar的应用程序

时间:2011-10-23 12:32:40

标签: iphone uitabbarcontroller uitabbar

我的iPhone应用程序是基于导航的应用程序。

客户需要将60%的应用转换为全局TabBar。 (即从应用程序视图中包含60%的一个标签栏)

那么,这里遵循的最佳做法是什么? 是否在Window中包含使用IB的TabBar? 或者添加更改整个应用程序的导航代码并推送TabBarController而不是常规的ViewController?

请向我提供想法。

感谢。

1 个答案:

答案 0 :(得分:0)

我使用了一个新的基于窗口的应用程序并输入以下代码:

这个想法是创建一个UITabBarController并将它放在NavigationController而不是ViewControllers上。

每个navigationController都会导航到自己的一组ViewContrllers。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UITabBarController* tabBarContoller = [[UITabBarController alloc]init];

    Cross1VC* cross1VC = [[Cross1VC alloc]initWithNibName:@"Cross1VC" bundle:nil];
    cross1VC.title = @"Cross 1";
    UINavigationController* crossNav = [[UINavigationController alloc]initWithRootViewController:cross1VC];
    crossNav.title = @"Cross";
    [cross1VC release];

    Part1VC* part1VC = [[Part1VC alloc]initWithNibName:@"Part1VC" bundle:nil];
    part1VC.title = @"Part 1";
    UINavigationController* partNav = [[UINavigationController alloc]initWithRootViewController:part1VC];
    partNav.title = @"Part";
    [part1VC release];


    NSArray* viewControllers = [NSArray arrayWithObjects:crossNav, partNav, nil];
    [tabBarContoller setViewControllers:viewControllers animated:YES];

    //tabBarContoller.delegate = [[SomeDelegateHandlerClass alloc]init]; // assign, not retain

    [self.window addSubview:tabBarContoller.view];
    //[tabBarContoller release]; // make instance variable and release in dealloc
    [self.window makeKeyAndVisible];
    return YES;
}
相关问题