【问题标题】:UITabBar with UINavigationController in code代码中带有 UINavigationController 的 UITabBar
【发布时间】:2010-05-11 11:54:23
【问题描述】:

我目前有一个带有 5 个屏幕的 UITabBar 调用 UIViews。那部分工作正常,但我想在其中几个中放入一个 UINavigationController。我找到了一些工作正常的教程,但它们都在 IB 中实现了它,如果可能的话,我想避免这种情况。

我不知道在哪里实现 UINavigationController,我应该在带有 UITabBar 的 App Delegate 中执行它并从 UIView 调用导航控制器还是应该在 UIView 类中创建它?

我尝试了大约 8 种不同的方法,但总是以导航栏不工作、根本没有导航栏或应用程序崩溃而告终。

目前我这样创建标签栏:

tabBarController = [[UITabBarController alloc] init];
ScreenA *screenA = [[ScreenA alloc] initWithNibName:@"ScreenA" bundle:nil];
//more here
tabBarController.viewControllers = [NSArray arrayWithObjects:screenA, ...., nil];
[window addSubview:tabBarController.view];

在 initWithNibName 我有这个:

self.title = @"Screen A";
self.tabBarItem.image = [UIImage imageNamed:@"someImage.png"];

【问题讨论】:

    标签: iphone objective-c uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    好吧,就这样吧……

        tabBarController = [[UITabBarController alloc] init];    

    searchTableViewController = [[SearchTableViewController alloc] init];
        UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
    [searchTableViewController release];                                                              
    
    searchMapViewController = [[SearchMapViewController alloc] init];   
    UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
    [searchMapViewController release];                                                    
    
    
    tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, nil]; 
    

    【讨论】:

    • 烦人的是我应该知道的,我在我的另一个应用程序中使用过它:( facepalm
    • @Andiih:这样,我没有成功用两个不同的名称命名导航栏和标签栏项目。有没有办法做到这一点?
    猜你喜欢
    • 1970-01-01
    • 2017-08-22
    • 2010-11-12
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多