gpt4 book ai didi

objective-c - 将导航栏添加到当前程序

转载 作者:行者123 更新时间:2023-11-29 04:33:25 25 4
gpt4 key购买 nike

我有一个带有包含三个选项卡的选项卡栏 Controller 的应用程序。我需要将导航 Controller 添加到第一个选项卡。我的 Root View Controller 是选项卡栏,那么如何添加导航栏?我已初始化导航栏,但不知道在哪里设置它。感谢任何可以提供帮助并询问您是否需要更多信息的人。这是我的应用程序 delegate.m:

#import "TACAppDelegate.h"
#import "FirstViewController.h"
#import "ThirdViewController.h"
#import "SecondViewController.h"

@implementation TACAppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* Initialize window view */
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

/* Initialize tab bar controller, add tabs controllers */
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [self initializeTabBarItems];
self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];
return (YES);
}

....

- (NSArray *)initializeTabBarItems
{
NSArray * retval;

/* Initialize view controllers */
FirstViewController *viewController1 = [[FirstViewController alloc] init];
SecondViewController *viewController2 = [[SecondViewController alloc] init];
ThirdViewController *viewController3 = [[ThirdViewController alloc] init];

/* Initialize navigation controllers */
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];



/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects:viewController1,viewController2,viewController3,nil];



return (retval);
}

@end

最佳答案

这是需要更改以在代码中执行此操作的行:

/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects:viewController1,viewController2,viewController3,nil];

在这里,您仍然将对原始 viewController1 的引用放入选项卡栏项目数组中。那不再是你想要的。您已经创建了导航 Controller 并将其 Root View Controller 设置为 View Controller 1,因此这是您需要放入选项卡栏项目列表中的顶级引用。您的新行将如下所示:

/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects: navigationController1,viewController2,viewController3,nil];

这将创建一个 Controller 层次结构,例如:

标签栏:[ 导航 Controller :[ VC1 ]、VC2、VC3 ]

关于objective-c - 将导航栏添加到当前程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11385490/

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