2013-02-05 12 views
4

在我的iPad應用程序中,我使用了tabBarController。我運行下面的代碼來選擇一個特定的標籤:圖標在更多選項卡中消失

[tabBarController setSelectedViewController:myNavigationController]; 

(我修改屬性的類UITabBarControllerselectedViewController,見apple docs

這工作完全;唯一的問題是,當用戶導航回「更多...」屏幕左上方的按鈕,對於之前選擇的選項卡中的圖標丟失:

an icon is missing

當我手動導航,有沒問題。圖標始終在「更多」屏幕中可見。只有當我使用方法setSelectedViewController時纔會出現此問題。

標籤欄項目創建如下:

newVC = [[SynchronizeViewController alloc] init]; 
newVC.tabBarItem = [[UITabBarItem alloc] 
    initWithTitle:NSLocalizedString(@"SYNCHRONIZE", @"synchronize tab label") 
    image:[UIImage imageNamed:@"02-redo.png"] tag:0]; 

已經有人遇到了同樣的問題,找到了一種方法來解決這個問題?提前致謝 !

+1

請發表您的setSelectedViewController方法。 – Balu

+0

@Sunny這是對應於'UITabBarController'屬性'selectedViewController'的setter。請參閱[doc](http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html) –

+0

請發佈圖像文件。 – holex

回答

2

能否請您添加一個方法來同步控制器:

- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated]; 
    AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; 
    UITableView *view = (UITableView *)appDelegate.tabBarController.moreNavigationController.topViewController.view; 
    [view reloadData]; 
} 
+0

是的,那有效!我們需要刷新'moreNavigationController'表視圖並顯示圖標。似乎是iOS中的錯誤? 非常感謝。 –

+0

不客氣!是的,我認爲這是iOS中的錯誤。 –

0

嘗試從項目中刪除文件。獲取一個乾淨的構建並將其添加回具有不同名稱的項目。

1

問題是,你自己創建UITabBarItem。從-tabBarItem的文檔:

該屬性第一次訪問時,UITabBarItem創建。

所以你不需要創建它,只是這樣做:爲解釋

newVC.tabBarItem.title = @"Your Title"; // Default is view controller's title. 
newVC.tabBarItem.image = yourImage; 

嘗試:出於某種原因,UITabBarController決定在內部重新創建所有標籤欄物品,還是什麼。而你的實例丟失了,使用了默認標題。或者也許只有圖像丟失了,誰知道。這被稱爲未定義的行爲

+0

非常感謝這個好主意,但我嘗試了它,並且圖標仍然丟失。 –

+0

但是,請按照此答案來防止其他意外的錯誤。 – Tricertops

+0

好的,謝謝你的幫助! –

相關問題