UINavigationController的不以的UITabBarController的的more

2019-08-03 19:20发布

我处理UINavigationControllers在我的应用程序,所有由处理UITabBarController 。 直到我控制器落入自动生成的“更多”标签,一切工作正常。

我在简单的例子复制的问题。 难道我做错了什么? 我想不通。

谢谢你的帮助。

#import <UIKit/UIKit.h>

@interface testAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
{
    UIWindow *window;
    UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end

@implementation testAppDelegate
@synthesize window, tabBarController;

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];

    UINavigationController *ctrl1 = [[[UINavigationController alloc] initWithNibName:nil bundle: nil] autorelease];
    ctrl1.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1] autorelease];

    UINavigationController *ctrl2 = [[[UINavigationController alloc] initWithNibName:nil bundle: nil] autorelease];
    ctrl2.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:2] autorelease];

    UINavigationController *ctrl3 = [[[UINavigationController alloc] initWithNibName:nil bundle: nil] autorelease];
    ctrl3.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:3] autorelease];

    UINavigationController *ctrl4 = [[[UINavigationController alloc] initWithNibName:nil bundle: nil] autorelease];
    ctrl4.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:4] autorelease];

    // This one won't work
    UINavigationController *ctrl5 = [[[UINavigationController alloc] initWithNibName:nil bundle: nil] autorelease];
    ctrl5.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostRecent tag:5] autorelease];

    // This one will work
    UIViewController *ctrl6 = [[[UIViewController alloc] initWithNibName:nil bundle: nil] autorelease];
    ctrl6.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:6] autorelease];

    tabBarController.viewControllers = [NSArray arrayWithObjects:ctrl1, ctrl2, ctrl3, ctrl4, ctrl5, ctrl6, nil];

    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
}

- (void)dealloc
{
    [tabBarController release];
    [window release];
    [super dealloc];
}

@end

Answer 1:

简短的回答:你不能嵌套导航控制器

较长的回答:你做错了。 一个更好的方式来创建你想要的东西是这样的:

NSMutableArray *viewControllers = [NSMutableArray array];

[viewControllers addObject:[[[ConverterViewController alloc] init] autorelease]];
[viewControllers addObject:[[[UINavigationController alloc]
                             initWithRootViewController:[[[CurrencyViewController alloc] init] autorelease]] autorelease]];
[viewControllers addObject:[[[UINavigationController alloc]
                             initWithRootViewController:[[[HistoryViewController alloc] init] autorelease]] autorelease]];
[viewControllers addObject:[[[UINavigationController alloc]
                             initWithRootViewController:[[[SetupViewController alloc] init] autorelease]] autorelease]];
[viewControllers addObject:[[[UINavigationController alloc]
                             initWithRootViewController:[[[HelpViewController alloc] init] autorelease]] autorelease]];
[viewControllers addObject:[[[LinksViewController alloc] init] autorelease]];

self.viewControllers = viewControllers;
self.customizableViewControllers = [viewControllers arrayByRemovingFirstObject];


@implementation HelpViewController

#pragma mark -
#pragma mark Initialization

- (id)init
{
    if ((self = [super initWithNibName:@"HelpView" bundle:nil]) != nil) {
        self.title = NSLocalizedString(@"Help", @"Help"); 
        self.tabBarItem.image = [UIImage imageNamed:@"question.png"];
    }

    return self;
}


Answer 2:

我想这个问题可能是您正在使用导航控制器直接推新的观点。 像这样:

[ctrl4 pushViewController:next animated:true];

但如果你是在更多的标签另一个导航控制器被激活。 你必须总是使用当前显示视图控制器的navigationController属性的当前导航控制器。

通过做这种方式,导航控制器标签栏控制器内工作得很好。



Answer 3:

当您设置viewControllers财产上的UITabBarController它会自动更换的视图控制器5起与moreNavigationController导航控制器。

我处理了类似的问题,我的自定义标签栏上。 该解决方案可以帮助你:

抑制moreNavigationController定制的UITabBarController



文章来源: UINavigationController doesn't work in a the moreNavigationController of a UITabBarController