簡體   English   中英

如何顯示uitabbarcontroller的標題

[英]How to Display title for uitabbarcontroller

我使用以下代碼創建了uitabbarview控制器

在uitabbar控制器中,我想顯示每個視圖的圖塊

請讓我知道如何為每個視圖添加標題(標簽欄項)

myTabBarController = [[UITabBarController alloc] init];

    MyDialerViewController *aDialerViewController = [[MyDialerViewController alloc]init];
    MyCallLogViewController *aCallLogViewController = [[MyCallLogViewController alloc] init];
    TemplateViewController *aTemplateViewController = [[TemplateViewController alloc] init];    


    NSArray* controllers = [NSArray arrayWithObjects:aDialerViewController, aCallLogViewController, aTemplateViewController, nil];
    myTabBarController.viewControllers = controllers;
    myTabBarController.delegate = self;
    myTabBarController.selectedIndex = 0;

    [controllers release];
    [aDialerViewController release];
    [aCallLogViewController release];
    [aTemplateViewController release];

    [self.window addSubview:myTabBarController.view];

    [self.window makeKeyAndVisible];
self.viewcontroller.tabBarItem = // a UITabBarItem instance

制作一個UITabBarItem的實例

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITabBarItem_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITabBarItem

  • (id)initWithTitle:(NSString *)標題圖像:(UIImage *)圖像標簽:(NSInteger)標簽

您可以將其寫在每個viewcontroller的初始化函數中。

我直接在appDelegate中設置navcontroller的標題。

aDialerViewController.title = NSLocalizedString(@"Dialer Title", @"Dialer Title");
aCallLogViewController.title = @"Title";
aTemplateViewController.title = @"Title";

我還要在那些viewControllers的viewDidLoad方法中進行設置。

對我來說很好。 記住要本地化,以防萬一您將來需要它。 (如果不打算這樣做,則應調查一下)

暫無
暫無

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

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