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

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

最佳答案

你可以打电话

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


在您的-viewDidLoad-awakeFromNib方法中。最好使用后者而不是前者。

关于objective-c - 标签栏项目的标题未显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7438515/

10-13 03:57