2011-09-05 61 views
3

所以這裏是我在我的應用程序中設置的東西。我有一個UINavigationControllerUITabBarController作爲rootViewControllerrootViewController有3個標籤。我已經嘗試了許多不同的方式來設置標題,範圍從:無法設置UINavigationController標題

self.title = @"title";

self.navigationController.title = @"title";

self.navigationItem.title = @"title";

沒有它的工作原理

這是爲什麼?

UPDATE:

一些奇怪的原因self.parentViewController.title = @"Map";實際工作....

+0

看看http://stackoverflow.com/questions/6644555/uitabbaritem-title-vs-uinavigationcontroller-title解決你的問題。 – Manny

回答

0

self.title應該是你用什麼。

1.)你什麼時候想改變標題?例如,當按下一個標籤按鈕?

2.)你在哪裏放這個代碼?這應該是在viewDidLoad方法

+0

是的,我確實把它放在viewDidLoad as self.title = @「Map」;它不起作用。我想在視圖最初顯示時顯示標題..否則沒有標題,因爲現在它只顯示根視圖控制器作爲標題 – adit

+1

'self.title'應該在'init'中設置,因爲它可以用於在視圖加載之前。就像在標籤欄中一樣,即使僅在更改標籤時才加載視圖,也會使用標籤的標題。 – gcamp

+0

看到我的更新... – adit

-2

它來了....

您必須編寫下面一行到的appdelegate添加tabbarcontroller ..

mTabBar = [[UITabBarController alloc] init]; 
    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:3]; 


    TSDetailTaskController *mTSDetailTaskController = [[TSDetailTaskController alloc]initWithNibName:@"TSDetailTaskController" bundle:nil]; 
    UINavigationController *mTaskNavBar=[[UINavigationController alloc]initWithRootViewController:mTSDetailTaskController]; 
    [email protected]"Task List"; 
    mTaskNavBar.tabBarItem.image =[UIImage imageNamed:@"glyphicons_114_list.png"]; 
    [mTSDetailTaskController release]; 

    mTSSearchController=[[TSSearchController alloc]initWithNibName:@"TSSearchController" bundle:nil]; 
    UINavigationController *mSearchNavBar=[[UINavigationController alloc]initWithRootViewController:mTSSearchController]; 
    [email protected]"Search"; 
    mSearchNavBar.tabBarItem.image=[UIImage imageNamed:@"glyphicons_009_search.png"]; 
    [mTSSearchController release]; 

    TSSettingController *mTSSettingController = [[TSSettingController alloc]initWithNibName:@"TSSettingController" bundle:nil]; 
    UINavigationController *mSettingNavBar=[[UINavigationController alloc]initWithRootViewController:mTSSettingController]; 
    [email protected]"Setting"; 
    mSettingNavBar.tabBarItem.image=[UIImage imageNamed:@"glyphicons_280_settings.png"]; 
    [mTSSettingController release]; 


    [localViewControllersArray addObject:mTaskNavBar]; 
    [localViewControllersArray addObject:mSearchNavBar]; 
    [localViewControllersArray addObject:mSettingNavBar]; 

    [mTaskNavBar release]; 
    [mSearchNavBar release]; 
    [mSettingNavBar release]; 


    mTabBar.viewControllers = localViewControllersArray; 
    mTabBar.view.autoresizingMask==(UIViewAutoresizingFlexibleHeight); 

    [localViewControllersArray release]; 


    [window addSubview:mTabBar.view]; 
    [self.window makeKeyAndVisible]; 
    return YES; 

我想,烏爾創建基於項目烏爾UINavigation控制器類型......

然後在烏爾RootViewController的的 「viewDidLoad中」 嘗試self.title

希望這個厄爾幫助你出來..

+0

爲什麼我必須再次在其上添加另一個UINavigationController?這樣做給了我這個http://imgur.com/kPQg5 – adit

+0

是啊,不要這樣做,這是完全錯誤的。 – WrightsCS

2

我猜你想要的是設置文本出現在導航欄的中心。如果是這樣,navigationItem絕對不是你想要的。這是爲了在導航欄中設置按鈕。

設置標題的不太明顯的部分是,將出現在導航欄上的文字是ViewController是頂部的標題。換句話說,最後的ViewController被推。所以你想要做的就是在你的ViewContoller中設置self.title。你可以這樣做ViewContollerinitviewDidLoad

+0

爲此,請確保您的ViewController通過Custom Class屬性在Interface Builder的Identity Inspector中連接。 – jazzinthemorning

2

我試着NSLogging導航欄中的每個標題屬性,最終爲我設置navBar.topItem.title屬性。當然,navBar是在我的IB中對UINavigationBar的引用。