我在我的应用程序中处理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
答案 0 :(得分:2)
简答:您无法嵌套导航控制器
更长的答案:你做错了。创建所需内容的更好方法是:
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;
}
答案 1 :(得分:0)
我认为问题可能是您直接使用导航控制器来推送新视图。像这样:
[ctrl4 pushViewController:next animated:true];
但是如果你在更多选项卡中,则另一个导航控制器处于活动状态。您必须始终使用当前显示的视图控制器的navigationController属性获取当前导航控制器。
通过这种方式,导航控制器可以在标签栏控制器内正常工作。
答案 2 :(得分:0)
当你在UITabBarController上设置viewControllers属性时,它会自动用moreNavigationController替换视图控制器5上的导航控制器。
我在自定义标签栏上处理了类似的问题。此解决方案应该可以帮助您:
Suppress moreNavigationController in custom UITabBarController