iphone – 将UITabBarController与UINavigationController结合使用

前端之家收集整理的这篇文章主要介绍了iphone – 将UITabBarController与UINavigationController结合使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试使用带有导航栏的“选项卡式应用程序”.使用默认标签栏工作正常,但我只是无法gat导航栏.我找到了一些关于推动导航栏和类似东西的东西,但我发现的所有东西都是几年前的,所以不要帮助我.最近的东西已经过时,因为iOS5和 Xcode的新版本..

任何人都能指出我正确的方向来结合一个来解决这个问题吗?

请记住以下事实:

>我正在为iOS5开发
>我正在使用Xcode 4.2

解决方法

以下是如何以编程方式实现它.

在[appName] -Info.plist中删除对主xib的引用

在main.m中,加载您的委托:

int retVal = UIApplicationMain(argc,argv,nil,@"myAppDelegate");

在app delegate中,加载tabBar,导航控制器和navigationController中的视图.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // create window since nib is not.
    CGRect windowBounds = [[UIScreen mainScreen] applicationFrame];
    windowBounds.origin.y = 0.0;
    [self setWindow:[[UIWindow alloc] initWithFrame:windowBounds]];

    // View Controllers for tabController (one viewController per tab)
    NSMutableArray *viewControllers = [[NSMutableArray alloc] init];

    // first tab has view controller in navigation controller
    FirstView *firstView = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstView];
    [viewControllers addObject:navController];

    SecondView *secondView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
    [viewControllers addObject:secondView];    

    // create the tab controller and add the view controllers
    UITabBarController *tabController = [[UITabBarController alloc] init];
    [tabController setViewControllers:viewControllers];

    // add tabbar and show
    [[self window] addSubview:[tabController view]];
    [self.window makeKeyAndVisible];
    return YES;
}

猜你在找的Xcode相关文章