2017-09-19 24 views
1

如何更改UITabBarController中的視圖控制器。 UITabBarController創建於Storyboard。即想要刪除最後一個項目。啓用到否UITabBarItem只會禁用按鈕,但不會隱藏它。如何更改UITabBarController中的項目

enter image description here

+0

您的UITabBarController集標識符什麼ü想要做刪除bar bar button item from tab bar or load different VC when a bar button item pressed ?? ?? –

+0

@ /jános:Up投票和收藏你的問題將保持眼睛在這:)這聽起來很有趣 –

+1

@SandeepBhandari baritem只是視圖控制器的財產。所以刪除視圖控制器刪除baritem以及 –

回答

3

首先,你需要獲得viewcontrollers一個數組,改變數組。修改後分配回的UITabBarController

NSMutableArray *viewCotrollers = [[NSMutableArray alloc]initWithArray:[tbc viewControllers]]; 
    [viewCotrollers removeLastObject]; 
    [tbc setViewControllers:viewCotrollers animated:YES]; 

要獲得TabBarController你可以用下面的代碼

UITabBarController *tbc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"tabBarController"]; 

藤本則需要在故事板

+0

+1。我不知道設置UITabBarController的ViewControllers數組將重置其標籤欄項:)好的一個因此+1。學到了新東西 –