gpt4 book ai didi

iphone - UINavigationController 在 UITabBarController 的 moreNavigationController 中不起作用

转载 作者:行者123 更新时间:2023-12-03 19:20:58 25 4
gpt4 key购买 nike

我正在应用程序中处理 UINavigationControllers,所有这些都由 UITabBarController 处理。一切工作正常,直到我的 Controller 落入自动生成的“更多”选项卡。

我在简单的示例中重现了该问题。难道我做错了什么?我想不通。

感谢您的帮助。

#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

最佳答案

简短回答:不能嵌套导航 Controller

更长的答案:你做错了。创建您想要的内容的更好方法如下:

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;
}

关于iphone - UINavigationController 在 UITabBarController 的 moreNavigationController 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1380503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com