问题描述
限时送ChatGPT账号..在 iOS 中,TabBarController 中的 TabBar 属性是只读的.如何将自定义项目与特定视图控制器相关联?如何访问 tabBar 内的 UITabBarItems?
In iOS, the TabBar property in the TabBarController is read only. How can I associate a custom item with a particular view controller? How do I access the UITabBarItems inside the tabBar?
像这样
CustomView *custom = [[CustomView alloc] init];
UITabBarItem *customTab = [[UITabBarItem alloc] initWithTitle:@"Custom" image:[UIImage imageNamed:@"custom.png"] tag:0];
SecondView *second = [[SecondView alloc] init];
UITabBarItem *secondTab = [[UITabBarItem alloc] initWithTitle:@"Next" image:[UIImage imageNamed:@"next.png"] tag:1];
NSArray *views = [NSArray arrayWithObjects:custom,second,nil];
[tabBarController setViewControllers:views];
//how do I set the individual TabBarItems (customTab,secondTab) to be associated
//with the views in question? tabBarController.tabBar is read only
推荐答案
在每个视图控制器中,你可以设置一个 tabBarItem 属性.如果视图控制器归 UITabBarViewController 所有,则标签栏上的关联项将相应更新.
Inside each view controller, you can set a tabBarItem property. If the view controller is owned by a UITabBarViewController the associated item on the tab bar will be updated accordingly.
像这样
-(void)viewDidLoad {
[super viewDidLoad];
UITabBarItem *tbi = [[UITabBarItem alloc] initWithTitle:yourTitle image:yourIcon tag:yourTag];
[self setTabBarItem:tbi]
[tbi release];
}
很明显,您不限于在 viewDidLoad 方法中执行此操作.
You are not restricted to perform this operation in the viewDidLoad method, obviously.
这篇关于以编程方式设置自定义 UITabBarItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论