如何以编程方式设置标签栏项目的标题?
我尝试了这个,但它不起作用,我看不到选项卡栏项目。我该如何解决这个问题?感谢您的帮助。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myTabBarController = [[UITabBarController alloc] init];
tab1 = [[ZiyaretFormTab1 alloc] initWithNibName:@"ZiyaretFormTab1" bundle:nil];
tab2 = [[ZiyaretFormTab2 alloc] initWithNibName:@"ZiyaretFormTab2" bundle:nil];
tab3 = [[ZiyaretFormTab3 alloc] initWithNibName:@"ZiyaretFormTab3" bundle:nil];
tab4 = [[ZiyaretFormTab4 alloc] initWithNibName:@"ZiyaretFormTab4" bundle:nil];
tab5 = [[ZiyaretFormTab5 alloc] initWithNibName:@"ZiyaretFormTab5" bundle:nil];
myTabBarController.viewControllers = [NSArray arrayWithObjects: tab1, tab2,tab3,tab4,tab5,nil];
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
[tabItem setTitle:@"theTitle"];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=0;
}
I try this but it not works I can not see tab bar item..How can I solve this problem? Thanks for your help.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myTabBarController = [[UITabBarController alloc] init];
tab1 = [[ZiyaretFormTab1 alloc] initWithNibName:@"ZiyaretFormTab1" bundle:nil];
tab2 = [[ZiyaretFormTab2 alloc] initWithNibName:@"ZiyaretFormTab2" bundle:nil];
tab3 = [[ZiyaretFormTab3 alloc] initWithNibName:@"ZiyaretFormTab3" bundle:nil];
tab4 = [[ZiyaretFormTab4 alloc] initWithNibName:@"ZiyaretFormTab4" bundle:nil];
tab5 = [[ZiyaretFormTab5 alloc] initWithNibName:@"ZiyaretFormTab5" bundle:nil];
myTabBarController.viewControllers = [NSArray arrayWithObjects: tab1, tab2,tab3,tab4,tab5,nil];
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
[tabItem setTitle:@"theTitle"];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在进入选项卡的每个视图控制器(ZiyaretFormTab1 到 ZiyaretFormTab5)中,将此代码插入到 initWithNib 或 viewDidLoad 函数中。
In each of your view controllers that go into the tabs (ZiyaretFormTab1 to ZiyaretFormTab5), insert this code into initWithNib or viewDidLoad functions.
选项卡栏标题由各自的视图控制器控制。设置标题的最简单方法是在该选项卡的视图控制器中,而不是尝试直接在选项卡中设置它。
每个视图控制器都有一个
title
属性,用于设置选项卡栏和导航栏中的标题。它还具有一个tabBarItem
属性,该属性拥有自己的title
属性,如果您只想设置选项卡而不影响导航栏,则可以设置该属性。因此,在 viewController 的 viewDidLoad 中,您可以编写:
Tab bar titles are controlled by their respective view controllers. The easiest way to set the title is from within the view controller for that tab, instead of trying to set it in the tab directly.
Each view controller has a
title
property which is used to set the title in tab bars and navigation bars. It also has atabBarItem
property which has it's owntitle
property that you can set if you want to just set the tab and not affect navigation bars.So in the viewDidLoad of your viewController, you could write:
将选项卡设置放入 AppDelegate。
把你的名字和制服图标信息访问这里:
Put the tab settings to AppDelegate.
Put your name and icon information uniforms visit here:
您是否尝试
在分配并初始化它之后进行设置?
Have you tried to set
after allocating and initialising it.