2013-02-04 20 views
1

我有一個應用程序,它有一個UITabbarController,其中只有一個TabBarItem,即「Home」。在UITabbarController中添加新的TabBarItems

現在的問題是,當我在我的主頁選項卡欄項目可以添加更多TabbarItem的不同ViewControllers到我現有的UITabbarcontroller

這裏是更詳細的例子:

我只有一個「Home標籤」。我在Home標籤上打了一個服務,然後服務器說在TabBar上也必須有ViewController1ViewController2。然後我可以在運行時創建它。如果是,任何人都可以描述!

感謝

回答

1
NewViewController* vc1 = [[NewViewController alloc] init]; 

    vc1.tabBarItem.image = [UIImage imageNamed:@"icon.png"]; 
    vc1.tabBarItem.title = @"Title"; 

    NSMutableArray* controllers = [NSMutableArray arraywithArray :tabBarController.viewControllers]; 
    [controllers addObject:vc1]; 
    tabBarController.viewControllers = controllers; 

希望這有助於

+0

現在檢查,我剛剛編輯 – DivineDesert

+0

明白了。完善。像魅力一樣工作。謝謝一堆 – Shah

1

你必須創建一個新的NSMutableArray與現有的視圖的副本,然後釘在年底新的查看和設置選項卡控制器的觀點是新的副本。所以,如果你在現有的'單一'ViewController:

ViewController *newView = [[ViewController alloc]init]; 
NSMutableArray *views = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers]; 
[views addObject:newView]; 
self.tabBarController.viewControllers = views; 
相關問題