2013-09-26 44 views
3

我有UITabBarController並推動兩個視圖。我希望第一個視圖成爲默認值,並且按鈕在加載時處於「選定」狀態。的UITabBarController所選項目

我的問題是tabBarItem沒有選擇的背景時,它加載。我必須點擊它才能顯示選中的內容。我也爲標籤欄項目使用自定義圖像,並在每個視圖中配置它們,並將其添加到tabBarController中。

我使用這個設置選擇的項目:

_tabBarController.selectedViewController = [_tabBarController.viewControllers objectAtIndex:0]; 

的UITabBarItem獲取我添加到tabBarController每個視圖中創建:

-(UITabBarItem *)tabBarItem 
{ 
    return [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"tab_select_indicator_map.png"] tag:0]; 
} 

我怎麼也有tabBarItem顯示選擇的狀態?

+0

你有沒有找到一個解決問題了嗎?我推送一個tabbarcontroller並且最初的選項卡圖標未被選中(儘管視圖控制器正確顯示)。只在實際的選項卡圖標上點擊才能選中它。我以編程方式設置'selectedIndex'。 –

回答

1

使用下面顯示的代碼選擇tabBarItem當你的TabBar被加載。

[_tabBarController setSelectedIndex:0]; // your can set index as per your requirement. 

Eited:

確保您創建tabBarItem諸如此類

UITabBarItem* myTestingItem = [[UITabBarItem alloc] init]; 
[myTestingItem setFinishedSelectedImage: [UIImage imageNamed: @"btnTabItem-SelectedImage.png"] 
       withFinishedUnselectedImage: [UIImage imageNamed: @"btnTabItem.png"]]; 
+0

但它不會給tabBarItem「選擇」狀態。我仍然需要點擊才能顯示該狀態。 –

+0

@SteveSloka - 請檢查我編輯的答案:) – iPatel

+0

我更新了問題以顯示如何創建tabBarItem。現在我沒有設置未選擇的圖像,但是當我點擊時,我會得到一個。 –