在编程上更改Uitabbaritem的突出显示状态 - 目标C
-
29-09-2019 - |
题
我想知道如何在程序中选择使Uitabbaritem突出显示。这可能吗?
谢谢
解决方案
您可以更改选择哪个选项卡(也可以更改突出显示)轻松:
tabcontroller.selectedIndex = youNewIndexHere;
如果您的TabController在应用程序委托中(如果您在创建项目时使用Tab Bar应用程序模板是这种情况),则看起来像这样:
ProjectNameAppDelegate *appDelegate = (ProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabcontroller].selectedIndex = youNewIndexHere;
其他提示
如果您知道索引并以这样的方式编写塔巴尔:
NSMutableArray *item [[NSMutableArray alloc] init];
[items addObject: [[[UITabBarItem alloc] initAsULike] autorelease]; <--- init as you like here
...
[tabBar setItems:items animated:FALSE];
tabBar.selectedItem = [items objectAtIndex: your_index]; <--- write your index here
[items release];
我有一个在IB中创建的Uitabbar,但没有TabbarController。在我的Awakefromnib中,我只是将其初始化为这样的第一个项目:
[self.tabBar setSelectedItem:[[self.tabBar items] objectAtIndex:0]];
别忘了,在这种情况下,Uitabardelegate didSelectitem不会被调用。
不隶属于 StackOverflow