我正在使用MainStoryBoard编写程序。我有UITabBarController有5个选项卡。在每个uiviewcontroller的viewdidload中,我这样设置。但是,只有我去那个页面才会这样做。所以,我打算在我的AppDelegate中为所有标签做。我该如何以编程方式进行?我可以在UIStoryBoard中设置文本,但我需要以编程方式设置。
self.title = @"Some title";
答案 0 :(得分: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;
}