[英]How can I change a UITabBarItem title to the title from another UITabBarItem?
[英]How to change title of uitabBarItem either NIB file or prorammatically
以下是在viewDidLoad和viewWillAppear中編寫的代碼行,但仍未更改uitabbar項目標題。
[[self.userTabBarController.viewControllers objectAtIndex:1] setTitle:@“你的標題”];
userTabBarController的位置
IBOutlet UITabBarController *userTabBarController;
我的標簽欄有3個標簽,這些標簽與3個不同的viewController相結合,並且加載正常。
為什么沒有設置標題,代碼看起來似乎沒問題。
嘗試這個:
MyViewController *viewController = [self.userTabBarController.viewControllers objectAtIndex:1]
[viewController setTitle:@"Your title"];
由於這對你不起作用,我建議你去tabbarcontroller中的視圖控制器的實現文件,然后簡單地做:
self.title = @"my title";
在viewDidLoad方法中。
嘗試這個:
UITabBar *tabBar = self.userTabBarController.tabBar;
UITabBarItem *tabBarItem = [[tabBar items] objectAtIndex:0];
[tabBarItem setTitle:@"New Title"];
在NIB中,你的viewController的.m文件。像這樣改變你的initWithNibName方法。將會工作
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
[self setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"Aktuelles" image:[UIImage imageNamed:@"News.png"] tag:0]];
self.title = @"Aktuelles";
}
return self;
}
在awakeFromNib
方法中設置視圖控制器的title屬性:
- (void) awakeFromNib
{
self.title = "My Title";
}
您可以在IB上進行探索,或者如果您不想在appdelegate文件中進行設置,可以使用:
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:0] setTitle:@"new title 1"];
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:1] setTitle:@"new title 2"];
[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:2] setTitle:@"new title 3"];
編輯:因為我在Xp之前發布的人看起來一樣
UITabBarItem *item = [self tabBarItem];
item.title = @"Hi";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.