gpt4 book ai didi

iphone - 仅为一个不在 AppDelegate 中的 ViewController 以编程方式创建 TabBar

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

我想在我的应用程序中创建一个 tabBar,但只能在 detailView 中创建,而不是在 AppDelegate 中。我正在搜索如何在谷歌中执行此操作,但我发现的所有内容都在 AppDelegate.m

我正在尝试做这样的事情。这向我展示了一个带有两个按钮(没有名称)的选项卡栏,但我想从一个带有 tabBar 的 FirstViewController 转到两个项目之一 SecondViewController 或 ThirdViewController 带有一个带有一个 backItemButton 的导航栏以返回到 FirstViewController

- (void)viewDidLoad
{
[super viewDidLoad];
[self setupTabBar];
}
- (void) setupTabBar {

tabBars = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];


YPProfileViewController *profile = [[YPProfileViewController alloc] init];
YPProfileViewController *profile2 = [[YPProfileViewController alloc] init];

[localViewControllersArray addObject:profile];
[localViewControllersArray addObject:profile2];


tabBars.tabBarItem = profile2;
tabBars.viewControllers = localViewControllersArray;
tabBars.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight);


[self.view addSubview:tabBars.view];
}

最佳答案

至少这对我有用。

UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = @"FIRST";
vc1.view.backgroundColor = [UIColor blueColor];

UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = @"SECOND";
vc2.view.backgroundColor = [UIColor redColor];

UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = @[vc1,vc2];
tabBar.selectedIndex = 1;
tabBar.view.frame = CGRectMake(50, 50, 220, 320);

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

关于iphone - 仅为一个不在 AppDelegate 中的 ViewController 以编程方式创建 TabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18724193/

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