![](/img/trans.png)
[英]UINavigationController inside a UITabBarController with several views in the navigation controller
[英]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
並且rootViewController
是UINavigationController
,那么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.