将UITabBarController与UINavigationController组合 [英] Combine UITabBarController with UINavigationController

查看:146
本文介绍了将UITabBarController与UINavigationController组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用带有导航栏的选项卡式应用程序。使用默认的标签栏工作正常,但我只是不能gat导航栏。我发现一些东西,推动导航栏和东西,像这样,但所有的东西,我发现是几年前,所以不要帮助我。最近的东西是过时的,因为iOS5和新版本的Xcode ..



任何人可能指向我正确的方向结合一个解决这个问题? / p>

请记住以下事实:




  • 我正在开发iOS5

  • 我正在使用Xcode 4.2


解决方案



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



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

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

在应用程序委托中,加载tabBar,导航控制器和navigationController中的视图。 p>

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
/ /创建窗口,因为nib不是。
CGRect windowBounds = [[UIScreen mainScreen] applicationFrame];
windowBounds.origin.y = 0.0;
[self setWindow:[[UIWindow alloc] initWithFrame:windowBounds]];

//查看控制器的tabController(一个viewController每个标签)
NSMutableArray * viewControllers = [[NSMutableArray alloc] init];

//第一个选项卡在导航控制器中有视图控制器
FirstView * firstView = [[FirstView alloc] initWithNibName:@FirstViewbundle:nil];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:firstView];
[viewControllers addObject:navController];

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

//创建标签控制器并添加视图控制器
UITabBarController * tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:viewControllers];

//添加tabbar并显示
[[self window] addSubview:[tabController view]];
[self.window makeKeyAndVisible];
return YES;
}


I tried to use an "tabbed application" with a navigation bar in it. With the default the tab bar works fine, but I just can't gat a navigation bar. I found some stuff about pushing the navigation-bar and stuff like that, but all the stuff I found was some years ago, so don't gonna help me. And the recent stuff is outdated to, since iOS5 and the new version of Xcode..

Could anyone point me in the right direction to combine a to solve this problem?

Keep the following facts in mind please:

  • I'm developing for iOS5
  • I'm using Xcode 4.2

解决方案

Here's how you can achieve it programmatically.

Delete the reference to your main xib in [appName]-Info.plist

In main.m, load your delegate:

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

In the app delegate, load the tabBar, the navigation controller and the view in the 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;
}

这篇关于将UITabBarController与UINavigationController组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆