2014-09-20 46 views
0

我正在用MainStoryBoard編寫這樣的程序。我有UITabBarController與5個選項卡。在每個uiviewcontroller的viewdidload中,我這樣設置。但是,只有當我訪問該頁面時纔會這樣做。所以,我打算在我的AppDelegate中爲所有選項卡執行操作。我該如何編程?我可以在UIStoryBoard中設置文本,但我需要以編程方式進行設置。UIStoryboard更改選項卡欄按鈕文本

self.title = @"Some title"; 

enter image description here

回答

1

爲此,你應該先把故事板實例。然後從故事板獲取tabbar。在AppDelegate的以下方法中執行此操作。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; 
     UITabBarController *tabBar = [storyBoard instantiateInitialViewController] ; 
     NSLog(@"%@",tabBar.viewControllers); 
     // You will get list of your viewcontrollers added to tabbar .Get the instances of those view controllers and set title to them here. 
     return YES; 
    } 
+0

它爲我創建了該故事板的新實例。這不是應用程序將使用的實例,因爲我們在主界面中定義了故事板。 – 2014-09-21 00:04:12