簡體   English   中英

UITabBarController選中的項目

[英]UITabBarController selected item

我有UITabBarController並推送兩個視圖。 我希望第一個視圖是默認視圖,按鈕在加載時處於“選中”狀態。

我的問題是tabBarItem在加載時沒有選定的背景。 我必須點擊它來顯示所選的。 我也使用自定義圖像作為標簽欄項目,並在每個視圖中配置它們以添加到tabBarController。

我正在使用它來設置所選項目:

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

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

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

我怎樣才能讓tabBarItem顯示所選狀態?

加載tabBar時,使用以下顯示代碼選擇tabBarItem。

[_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"]];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM