iphone - 内部有 3 个选项卡且没有工作标题的导航 Controller

标签 iphone ios uinavigationcontroller uitabbarcontroller

我有 3 个选项卡和主导航 Controller 。我用代码实现:

UIViewController *monitorController   = [[[MonitorController   alloc] initWithNibName:@"MonitorController"   bundle:nil] autorelease];
UIViewController *dashboardController = [[[DashboardController alloc] initWithNibName:@"DashboardController" bundle:nil] autorelease];
UIViewController *settingsController  = [[[SettingsController  alloc] initWithNibName:@"SettingsController"  bundle:nil] autorelease];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:monitorController, dashboardController, settingsController, nil];

self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.tabBarController] autorelease];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];

我想在选择另一个点击时更改导航标题,但没有变体(见下文)不起作用(导航 Controller 上没有任何标题):

    self.title = DASHBOARD_TITLE; 

    self.navigationController.title = DASHBOARD_TITLE; 

我该如何解决这个问题?

最佳答案

UINavigationController 将显示它当前显示的 UIViewController 的标题,这就是您无法直接设置它的原因。 您可以尝试更改 UITabBarController 上的 title,但我不确定导航 Controller 是否会在它首次出现在屏幕上后更新它的标题。

但是,你真的需要那个架构吗?
通常 UITabBarControllerroot viewController,如果您需要 UINavigationControllers,它们位于 inside 需要的 Tab导航能力。
它被设计为以这种方式使用。

Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

引自UITabBarController Class Reference

关于iphone - 内部有 3 个选项卡且没有工作标题的导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8637810/

相关文章:

ios - 更改 ios 7 中 UIBarButtonItem 的背景颜色

ios - 在 iOS 8 中,如何在 la Mail.app 中实现长扫删除手势

ios - 强制 UIActivityViewController 以横向模式显示

swift - TabBar shouldSelectViewController 问题

ios - 在显示 UIAlertView 时处理摇动手势

ios - URLForUbiquityContainerIdentifier 总是返回 nil

ios 11 应用程序的颜色 (uinavigation)

iphone - UITextInput 的 Tokenizer,它是做什么用的?

iphone - 什么是强属性属性

iphone - 有没有办法在没有所有苹果东西的情况下将 ipa 文件安装到测试仪?