簡體   English   中英

UITabBarController中的UINavigationController,設置導航控制器標題

[英]UINavigationController within a UITabBarController, setting the navigation controller title

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

任何幫助將不勝感激。

先感謝您。

山姆

我最終得到了答案,它是:

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

適用於每個案例。

對我來說,以下工作正常:

appDelegateDidFinishLaunching:啟動控制器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";

祝好運。

self.title總是設置ViewController的rootViewController對象的tile。

如果你有viewController並且rootViewControllerUINavigationController ,那么self.title將設置UINavigationController的標題。

類似地,如果您使用UIViewController對象初始化了UITabViewController ,那么self.title將應用於UITabViewController UITabBar上索引處的標題對應按鈕。

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

查看docs中的UIViewController類。 有一個指向UINavigationItem的屬性,該屬性具有指向title的屬性。 如果指向導航項的指針返回nil,則必須未正確連接控制器。

暫無
暫無

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

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