15

在我的應用程序中,UITabBarController中有一個UINavigationController。一切工作正常,但我無法設置導航控制器的標題。我嘗試了幾種不同的方法並搜索,但似乎沒有解決這個問題的方法。UITabBarController中的UINavigationController,設置導航控制器標題

任何幫助將不勝感激。

提前謝謝。

山姆

+0

可能的重複:http://stackoverflow.com/questions/2760634/cocoa-touch-setting-uinavigationcontrollers-title-doesnt-work – 2012-03-05 15:56:37

+0

當然,你應該在視圖控制器中指定視圖控制器的標題,然後導航控制器將會應用正確的標題? – ader 2012-03-05 16:15:05

+0

我在視圖控制器中指定了標題。謝謝。山姆。 – shoughton123 2012-03-05 16:23:18

回答

38

我發現在最後的答案,那就是:

self.tabBarController.navigationItem.title = @"title"; 
2
self.navigationItem.title = @"Your Title" 

Works的每一個案件。

+1

我試過這個,它不起作用。 Thankyou雖然! – shoughton123 2012-03-05 16:19:16

+1

這應該工作。檢查以確保'self.navigationItem'不返回nil。如果無,請檢查您的連接。 – Gobot 2012-03-05 16:43:27

+0

如果你是從xib或從故事板加載,嘗試拖動一個navigationItem到你的viewController,如果沒有的話 – 2012-03-05 20:45:35

1

對於我下面的作品罰款:

發起appDelegateDidFinishLaunching:方法控制器:

UINavigationController *navContr1; 
UINavigationController *navContr2; 

UIViewController *viewController1, *viewController2; 

viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease]; 
viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease]; 



navContr1  = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease]; 
navContr2  = [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease]; 


self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
//self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navContr1, navContr2, nil]; 

self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 

與這個工作,在你的不同viewControllers initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - 方法可以更改與以下行標題:

self.title = @"Your Title"; 

祝你好運。

+0

不幸的是我已經在我的應用程序中相當深入,所以我不能使用這個確切的方法,但我不是'那不同。但是做自我。標題不起作用,self.title只是設置標籤欄的標題。雖然謝謝! – shoughton123 2012-03-05 16:18:33

+0

那麼self.navigationController.title = @「新標題」呢? – pmk 2012-03-05 16:57:29

0

看文檔中的UIViewController類。有一個房產指向UINavigationItem,然後有一個房屋指向title。如果指向導航項的指針返回nil,則必須沒有正確連接控制器。

0

self.title總是將你的ViewController的rootViewController對象的瓷磚。

如果您有viewController &的rootViewControllerUINavigationController,然後self.title將設置的UINavigationController稱號。

同樣,如果你已經初始化UITabViewControllerUIViewController對象,那麼self.title將適用於在指數相對應的按鈕標題,對UITabViewControllerUITabBar

因此表示,self.title適用於持有viewController的對象。

相關問題