2015-09-24 53 views
1

我有一個情景板場景是UITabBarController場景,它有大約5個標籤欄項目。我想要做的是根據用戶的捆綁設置刪除一兩個項目。所以,我創建了一個UITabBarController.h.m文件像這樣:從UITabBarController場景中刪除標籤欄項目

.H

#import <UIKit/UIKit.h> 

@interface LHTabBarController : UITabBarController 


@end 

.H

#import <Foundation/Foundation.h> 
#import "LHTabBarController.h" 

@implementation LHTabBarController 

-(void)viewDidLoad 
{ 

    /*NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [self.tabBarController viewControllers]]; 
    [tabbarViewControllers removeObjectAtIndex:1]; 
    [self.tabBarController setViewControllers: tabbarViewControllers];*/ 

    [super viewDidLoad]; 

} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [super viewDidAppear:animated]; 
} 

-(void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

@end 

,我在此連接類的UITabBarController我故事板。

我嘗試了註釋掉的代碼,但是這給了我一個數組,表示數組是空的。

如何從此類中刪除標籤欄項目?

回答

4

只要做到這一點:

當你在選項卡控制器這樣做,只簡單的自我比self.tabBarController

NSArray *actualItems= self.viewControllers; 

NSMutableArray *array=[[NSMutableArray alloc]initWithArray:actualItems]; 
[array removeObjectAtIndex:0]; 

    [self setViewControllers:array animated:YES]; 
+0

錯誤'爲「NSArray的」不可見@interface聲明選擇「removeObjectAtIndex: ' – user979331

+0

我的壞....你需要使它nsmutablearray ...我會更新我的答案 –

+0

NSArray不是可編輯陣列。你必須使它可變,然後刪除你不需要的對象 –

相關問題