简体   繁体   English

标签栏项目的标题未显示

[英]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): 如果我在应用启动时加载它,它看起来很棒(请参见图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: 如果在单击按钮时加载它,我的方式就如图2所示。请参见标题显示的内容和按钮的显示方式:

- (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 有谁知道为什么这样表现?] 1

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. -viewDidLoad-awakeFromNib方法中。 It might be better to use the latter instead of the former. 最好使用后者而不是前者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM