2012-06-04 174 views
0

我有一個的UITabBarController,想添加一個標籤,以使其消失的能力。我用XCode添加了2個選項卡。你可以通過程序添加第三個選項卡? 我知道像這樣的命令:添加/隱藏UITabBarItem

[self setViewControllers: [NSArray arrayWithObjects: x1, nil] animated: NO]; 

您可以檢索使用Xcode中添加第三種觀點的陣列? 謝謝


我無法加載視圖的代碼。我創建從故事板視圖控制器,當我嘗試從代碼加載它,我得到一個黑色的屏幕,使用此代碼:

ViewControllerA *x1 = [[ViewControllerA alloc] init]; 
[self setViewControllers:[NSArray arrayWithObjects: x1, nil] animated:NO]; 
+0

[請檢查如何隱藏欄按鈕] [1] [1]:http://stackoverflow.com/questions/10753233/make-invisible-a-uibarbuttonitem/ 10753376#10753376 – Mani

回答

3

是的,如果你使用[UITabViewController setViewControllers: animated:]您可以在包含前面兩個數組添加視圖控制器加上新的第三個。

例如,你可能想要做這樣的事情:

// assuming you've set an IBOutlet to your tab bar controller 
NSArray * currentSetOfViewControllers = [appTabBarController viewControllers]; 
if((currentSetOfViewControllers == NULL) || [currentSetOfViewControllers count] == 0)) 
{ 
    NSLog(@"I don't see any view controllers; is my tab bar controller outlet set properly?") 
} else { 
    NSMutableArray newSetOfViewControllers = [[NSMutableArray alloc] initWithArray: currentSetOfViewControllers]; 
    if(newSetOfViewControllers) 
    { 
     ViewControllerA *x1 = [[ViewControllerA alloc] init]; 
     if(x1) 
     { 
      [newSetOfViewControllers addObject: x1]; 

      [appTabBarController setViewControllers: newSetOfViewControllers]; 

      // release our alloc'd mutable array only if you do not have ARC turned on 
      [newSetOfViewControllers release]; 
     } 
    } 
} 

你可能也想給你的新視圖控制器帶有標題和圖像相關的標籤欄項目。檢查出[UITabBarItem initWithTitle: image: tag:]

我已經聯繫了蘋果文檔你,我希望能幫助!

+0

.........謝謝! – Antilope

0

創建代表自定義標籤欄以便創建視圖就像一個標籤欄,並設置圖1個的圖像視圖和3按鈕(1個按鈕組隱藏)添加後,在標籤欄控制器此視圖當u需要第三按鈕使第三個按鈕