UINavigationController 在 UITabBarController 的 moreNavigationController 中不起作用
我正在应用程序中处理 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
I'm dealing with UINavigationControllers
in my application, all handled by an UITabBarController
. Everything works fine until my controllers fall into the automatically generated "More" tab.
I reproduced the problem in the simplistic example. Am I doing something wrong? I can't figure out.
Thanks for your help.
#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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短的回答:你不能嵌套导航控制器
较长的回答:你做错了。创建你想要的东西的更好方法是这样的:
Short answer: you cannot nest navigation controllers
Longer answer: you are doing it wrong. A better way to create what you want goes like this:
我认为问题可能是您直接使用导航控制器来推送新视图。像这样:
但是,如果您在“更多”选项卡中,则另一个导航控制器处于活动状态。您必须始终使用当前显示的视图控制器的 navigationController 属性来获取当前的导航控制器。
通过这种方式,导航控制器可以在选项卡栏控制器内正常工作。
I think the problem might be that you are using the navigation controllers directly to push new views. Like this:
But if you are in the more tab another navigation controller is active. You must always get the current navigation controller using the navigationController property of the currently showing view controller.
By doing it this way, navigation controllers works just fine inside a tab bar controller.
当您在 UITabBarController 上设置 viewControllers 属性时,它将自动将视图控制器 5 及以上的导航控制器替换为 moreNavigationController。
我在自定义标签栏上处理了类似的问题。此解决方案应该可以帮助您:
在自定义 UITabBarController 中抑制 moreNavigationController
When you set the viewControllers property on the UITabBarController it will automatically replace the navigation controllers on the view controllers 5 onward with the moreNavigationController.
I dealt with a similar issue on my custom tab bar. This solution should help you:
Suppress moreNavigationController in custom UITabBarController