标签栏项目标题未显示

时间:2011-09-15 23:13:46

标签: objective-c ios xcode4

![我正在以编程方式创建标签栏控制器:

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];

如果我在应用程序启动时加载它,它看起来很棒(见图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;
}

如果我点击一个按钮加载它,我想这样做,它看起来像图2.看看标题是如何显示的,按钮似乎是截止的:

- (void)LoadView
{

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

有谁知道为什么会出现这样的行为?] 1

1 个答案:

答案 0 :(得分:1)

你可以打电话

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

采用-viewDidLoad-awakeFromNib方法。使用后者而不是前者可能会更好。