Troy Compton
Troy Compton

Reputation: 103

Title of tab bar items not showing

![I am creating a tab bar controller programmatically:

tabBarController = [[UITabBarController alloc] init];

FirstViewController* vc1 = [[FirstViewController alloc] init];

SecondViewController* vc2 = [[SecondViewController alloc] init];

vc1.title = @"Dallas";//[[NSUserDefaults standardUserDefaults] objectForKey:@"Citynamefrmhome"];
vc1.tabBarItem.image = [UIImage imageNamed:@"Dealss.png"];

vc2.title = @"My Vouchers";
vc2.tabBarItem.image = [UIImage imageNamed:@"nav_voucher_S.png"]; 

NSArray* controllers = [NSArray arrayWithObjects:vc1,vc2, nil];

tabBarController.viewControllers = controllers;

[self.view addSubview:tabBarController.view];

[vc1 release];
[vc2 release];

if I load it when the app starts, it looks great (look at figure 1):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    autoMagically = [[AutoMagically alloc] initWithNibName:nil bundle:nil];

    //self.window.rootViewController =  self.dummyView;
    [self.window addSubview:autoMagically.view];
    [self.window makeKeyAndVisible];

    return YES;
}

if I load it when a button is clicked, the way i wanna do it, it looks like figure 2. See how the titles arent showing and the buttons seem to be getting cutoff:

- (void)LoadView
{

    AutoMagically *autoMagic = [[AutoMagically alloc]
                                          initWithNibName:nil bundle:nil];
    self.autoMagically = autoMagic;
    [self.view insertSubview:autoMagic.view atIndex:0];
    [autoMagic release];
}

Does anyone know why this is behaving like this?]1

Upvotes: 1

Views: 974

Answers (1)

CodaFi
CodaFi

Reputation: 43330

You can call

[[[self.parentViewController.tabBarController.tabBar.items objectAtIndex:/*a number based on what tab it was ex: 2*/]setTitle:@"string"];

in your -viewDidLoad or -awakeFromNib methods. It might be better to use the latter instead of the former.

Upvotes: 1

Related Questions