2010-06-17 67 views

回答

12

嘿你要設置的標籤欄按鈕或與該選項卡關聯的視圖控制器的標題?

如果你正在尋找的第一件事再去做這樣的:

UITabBarItem *tabItem = [[[tabBarController tabBar] items] objectAtIndex:yourIndex]; 
[tabItem setTitle:@"theTitle"]; 

否則mihirpmehta是正確的。

希望這會有所幫助。

+1

我試圖設置標籤欄按鈕的標題。 我剛剛做的笏只是提供 self.title = @「Title」; at viewdidload .. 和標籤欄以及viewcontroller的標題已被設置爲「標題」。 是否正確? – iscavengers 2010-06-17 11:37:59

+0

@ shishir.bobby不能說是否合適 – 2010-06-17 11:41:45

+0

不需要在兩個地方設置標題......任何一個都足夠了...... – 2010-06-18 06:15:24

0

可以初始化並使用以下功能使用UITabBarItem對象:

- (id)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag; // selected image autogenerated 
- (id)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag 

然後你就可以調用這個方法您的TabBar對象:

- (void)setItems:(NSArray *)items animated:(BOOL)animated; 

其中物品ID的陣列,其你已經添加了所有的tabBarItem對象。如果需要使用,還有一個UITabBarItem的badgeValue屬性。

+0

感謝的人, 我只需要programmatially提供的名字,其餘的將是相同的... 任何其他方式提供手動標題??? – iscavengers 2010-06-17 10:30:08

5

OR

[(UIViewController *)[tabBarController.viewControllers objectAtIndex:1] setTitle:@"Title1"]; 
+0

這是正確的答案...不投票它只是因爲你不明白它,或它不符合你的意見。 – 2010-06-18 06:12:15

0

如果您UIViewController被包裹在一個UINavigationController,請執行下列操作:

self.navigationController?.tabBarItem.title = "Awesome Title" 
相關問題