2014-03-29 2 views
1

UITabBarController으로 작업 할 때 다음과 같은 문제가 있습니다. 각 탭의 모든보기 컨트롤러에 대한 제목으로 주어진 문자열을 갖고 싶습니다. 이것은 분명히 storyboard 내에 설정할 수 없습니다.UITabBarController에서 프로그래밍 방식으로 제목 설정

그물을 검색하여이 거의 작동하는 해결책을 발견했습니다. 개별보기 컨트롤러 각각에 다음 유형의 코드를 삽입합니다.

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    UITabBarItem *tabBarItem; 
    tabBarItem=[[UITabBarItem alloc] initWithTitle:nil 
              image:[self imageFromText:@"My Tab Title" 
                   withFont:[UIFont systemFontOfSize:17.0]] tag:0]; 
    self.tabBarItem=tabBarItem; 
} 

문제는 모든 제목이 사용자가 모든 탭을 탭한 경우에만 원하는대로 설정된다는 것입니다.

물론 이것은 영구적 인 해결책이 아닙니다. 앱이 시작될 때 모든 제목이 올바르게 표시되도록해야합니다.

누구나 어떻게 할 수 있습니까?

+0

나는 당신을 도울 수 있기를 바랍니다. –

답변

0

AppDelegate에서 변경할 수 있습니다.

3이 있다면 TabBarIcons :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 

    [[tabBarController.viewControllers objectAtIndex:0] setTitle:@"Your "]; 
    [[tabBarController.viewControllers objectAtIndex:1] setTitle:@"title "]; 
    [[tabBarController.viewControllers objectAtIndex:2] setTitle:@"here"]; 

    [[[tabBarController.viewControllers objectAtIndex:0] tabBarItem] setImage:[[UIImage imageNamed:@"first"] imageWithRenderingMode:UIImageRenderingModeAutomatic]]; 
    [[[tabBarController.viewControllers objectAtIndex:1] tabBarItem] setImage:[[UIImage imageNamed:@"second"] imageWithRenderingMode:UIImageRenderingModeAutomatic]]; 
    [[[tabBarController.viewControllers objectAtIndex:2] tabBarItem] setImage:[[UIImage imageNamed:@"third"] imageWithRenderingMode:UIImageRenderingModeAutomatic]]; 

    return YES; 
} 
+1

UITabBarController를 서브 클래 싱하여 종료했습니다. 하지만 내가 한 것은 당신의 제안과 비슷합니다. – Michel