簡體   English   中英

標簽欄項目的標題未顯示

[英]Title of tab bar items not showing

![我正在以編程方式創建標簽欄控制器:

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方法中。 最好使用后者而不是前者。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM