Tabbar button title displays only after the tab button is clicked

Discussion in 'iOS Programming' started by kingthong, Nov 18, 2010.

  1. kingthong macrumors member

    Sep 20, 2010
    Somewhere but not here.
    This is a rather unusual problem and i'm sure there is a simple fix for it.

    I read the Apple Docs on View Controllers and combining View Controllers. So i copy pasted the code available for using a Tabbar and a Navigation Controller together, into Xcode.

    Here's the code:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {
       tabBarController = [[[UITabBarController alloc] init] autorelease];
       MyViewController1* vc1 = [[[MyViewController1 alloc] init] autorelease];
       MyViewController2* vc2 = [[[MyViewController2 alloc] init] autorelease];
       MyViewController3* vc3 = [[[MyViewController3 alloc] init] autorelease];
       MyNavRootViewController* vc4 = [[[MyNavRootViewController alloc] init] autorelease];
       UINavigationController* navController = [[[UINavigationController alloc]
                               initWithRootViewController:vc4] autorelease];
       NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, navController, nil];
       tabBarController.viewControllers = controllers;
       // Add the tab bar controller's current view as a subview of the window
       window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
       [window addSubview:tabBarController.view];
    The program opens fine, but the name for each tabbar button appears only after it's clicked. The reason is because i've specified the self.title in the viewDidLoad. i tried specifying it in the LoadView and the awakeFromNib functions as well, but the problem persisted .

    Any suggestions?
  2. KoolStar macrumors demi-god


    Oct 16, 2006
    Why not just set the titles of each view after you allocate them.
  3. kingthong, Nov 18, 2010
    Last edited: Nov 18, 2010

    kingthong thread starter macrumors member

    Sep 20, 2010
    Somewhere but not here.
    yup got it. for some reason i didn't think of setting titles while allocating. thanks!

Share This Page