gpt4 book ai didi

带有标签栏和导航 Controller 的 iOS 应用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:45:22 26 4
gpt4 key购买 nike

在创建我的第一个 iPhone 应用程序的过程中,我注意到来自 Apple 的示例要么有标签栏,要么有导航栏,但从来没有两者都有。

这有可能吗?

所以我这里有一个带有 3 个按钮的标签栏,我现在如何向我的整个应用程序添加一个导航 Controller ?

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

UIViewController *activityViewController = [[[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:nil] autorelease];
UIViewController *agendaViewController = [[[AgendaViewController alloc] initWithNibName:@"AgendaViewController" bundle:nil] autorelease];
UIViewController *settingsViewController = [[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil] autorelease];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:activityViewController, agendaViewController, settingsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

编辑:

我真的没有关注,所以在我的 appdelegate 中我创建了一个 navigationController 并将其用作 rootViewController。

然后我创建了一个 tabBarController 并将其添加到我的窗口

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

UINavigationController *mainViewController = [[UINavigationController alloc] init];
self.mainViewController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];

self.window.rootViewController.title = @"test";

MainViewController *tabBarController = [[MainViewController alloc] init];
[self.window addSubview:tabBarController.view];

但是每当我运行时,我都会得到错误"

Pushing a navigation controller is not supported

我还遗漏了什么吗?

最佳答案

您可以创建一个导航 Controller ,然后创建一个 tabBarController 并使用以下命令将您的导航 Controller 添加到其中

 //incase you have 2 navigation controllers
tabBarController.viewControllers=[NSArray arrayWithObjects:navigationController1, navigationController2, nil ];

关于带有标签栏和导航 Controller 的 iOS 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10430642/

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