gpt4 book ai didi

ios - 如何为选项卡栏 View Controller 中的第一个选项卡获取新的 View Controller 而不是父 View ?

转载 作者:行者123 更新时间:2023-11-30 14:19:32 24 4
gpt4 key购买 nike

我在将选项卡栏 Controller 用于 View Controller 时遇到了问题。

这是我的问题

我有一个 View Controller ,我嵌入了一个选项卡栏 Controller ,并为其添加了四个选项卡,并为其他三个选项卡创建了三个 View ,这是我的确切问题。我不希望我的第一个选项卡栏 Controller 选择默认值,如果我单击第一个选项卡,我想显示其他 View ,它不应该显示我的父 View ,而我在父 View 中显示所有选项卡。

请给我一些解决方案来克服这个问题。希望我的问题细节清楚。

最佳答案

不知怎的,我能够理解你的问题。有时不发布代码就很难确定确切的问题。

我与您共享一个代码,假设应用程序启动一个 View Controller 作为“登录 View Controller ”,后面是“仪表板 View Controller ”。现在您想在用户登录后使用四个不同的选项卡显示 TabBar。

请在仪表板 View Controller ViewDidLoad 中调用以下方法“setUpTabBar”。

- (void)setUpTabBar
{

UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = @"Tab1";
vc1.view.backgroundColor = [UIColor clearColor];
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:vc1];
nav1 =[self setTrasparentNav:nav1];

UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = @"Tab2";
vc2.view.backgroundColor = [UIColor clearColor];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:vc2];
nav2 =[self setTrasparentNav:nav2];


UIViewController *vc3 = [[UIViewController alloc] init];
vc3.title = @"Tab3";
vc3.view.backgroundColor = [UIColor clearColor];
UINavigationController *nav3 =[[UINavigationController alloc] initWithRootViewController:vc3];
nav3 =[self setTrasparentNav:nav3];

UITabBarController *tabBar = [[UITabBarController alloc] init];

tabBar.viewControllers = @[nav1,nav2,nav3];
tabBar.selectedIndex = 0;
tabBar.view.frame = self.view.bounds;


[tabBar willMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];
}

您可以使用 tabBar.selectedIndex = 0 更改默认选定的选项卡栏;

希望这对您有帮助。

更新(根据调查问卷的要求):-

UIView *viewBottom=[[UIView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height- 60.0, self.view.bounds.size.width, 60.0)];
viewBottom.backgroundColor =[UIColor grayColor];


UIButton *btnAdd =[UIButton buttonWithType:UIButtonTypeSystem];
btnAdd.frame=CGRectMake(10, 10, 60.0, 40.0);

[viewBottom addSubview:btnAdd];

[self.view addSubview:viewBottom];

关于ios - 如何为选项卡栏 View Controller 中的第一个选项卡获取新的 View Controller 而不是父 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30659477/

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