gpt4 book ai didi

ios - 我添加了选项卡,但无法访问选项卡外的 View (ios)

转载 作者:行者123 更新时间:2023-11-29 10:48:11 26 4
gpt4 key购买 nike

我的原始应用有 5 个主屏幕 View ,主屏幕中的按钮会打开不同的其他 View 。

我没有使用 Storyboard。最初应用程序中没有标签。然后我添加了标签以使用

显示主屏幕
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] ;
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
UIViewController *viewController4 = [[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil];
UIViewController *viewController5 = [[FifthViewController alloc] initWithNibName:@"FifthViewController" bundle:nil];

UINavigationController *navigationController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
[navigationController1.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

UINavigationController *navigationController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
[navigationController2.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

UINavigationController *navigationController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
[navigationController3.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

UINavigationController *navigationController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
[navigationController4.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];

UINavigationController *navigationController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
[navigationController5.navigationBar setBackgroundImage:[UIImage imageNamed:@"upwhitebg.png"] forBarMetrics:UIBarMetricsDefault];


UITabBarController *tabBarController= [[UITabBarController alloc] init];
tabBarController.viewControllers = @[navigationController1, navigationController2,navigationController3,navigationController4,navigationController5];
//self.window.rootViewController = self.tabBarController;

UIWindow *window = [[UIApplication sharedApplication] delegate].window;
[window addSubview:tabBarController.view]

;

但是现在,当我单击主屏幕上的按钮时,如何显示选项卡外的 View ?以及如何从该 View 返回到第 5 个主屏幕选项卡 View 。

早些时候我使用这段代码来显示按下按钮时的 View

 listController = [[MenuListController alloc] initWithNibName:@"MenuListController" bundle:nil];
SUP101AppDelegate *delegate6 = [[UIApplication sharedApplication] delegate];
[delegate6.navController pushViewController:listController animated:YES]

最佳答案

您现在可以通过简单地将它们呈现在 tabController 上来启动其他 viewController。

listController = [[MenuListController alloc] initWithNibName:@"MenuListController" bundle:nil];
SUP101AppDelegate *delegate6 = [[UIApplication sharedApplication] delegate];
[self.tabBarController presentViewController:listController animated:YES completion:nil];

你还应该将 tabController 设置为 window RootViewController

self.window.rootViewController = tabBarController;
//[window addSubview:tabBarController.view]

关于ios - 我添加了选项卡,但无法访问选项卡外的 View (ios),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21622648/

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