gpt4 book ai didi

iphone - 如何设置iPhone中Tab栏项目1默认选中?

转载 作者:行者123 更新时间:2023-12-03 18:19:28 26 4
gpt4 key购买 nike

我是 iPhone 开发新手。我正在创建一个基于 View 的应用程序。我在我的 View 中添加了一个选项卡栏(而不是选项卡栏 Controller )。通过将选项卡栏项目的标记值设置为 1、2,我已在选项卡栏项目单击事件上加载了每个选项卡栏的 View 。

我希望默认选择选项卡栏 1。我应该为此做什么?

这是我的代码:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"didSelectItem: %d", item.tag);
[self activateTab:item.tag];
}

- (void)activateTab:(int)index {
switch (index) {
case 1:

self.tab1ViewController =[[tab1 alloc] initWithNibName:@"tab1" bundle:nil];

[self.view insertSubview:tab1ViewController.view belowSubview:tabbar1];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = tab1ViewController;
break;
case 2:

self.tab2ViewController =[[tab2 alloc] initWithNibName:@"tab2" bundle:nil];
[self.view insertSubview:tab2ViewController.view belowSubview:tabbar1];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = tab2ViewController;
break;
default:
break;
}
}

我在界面生成器中添加了选项卡栏。我可以在界面生成器中执行任何操作吗?

最佳答案

[tabBar setSelectedItem:[tabBar.items objectAtIndex:item.tag]];

关于iphone - 如何设置iPhone中Tab栏项目1默认选中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2325780/

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