我有 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 是否会在它首次出现在屏幕上后更新它的标题。
但是,你真的需要那个架构吗?
通常 UITabBarController
是 root viewController
,如果您需要 UINavigationControllers
,它们位于 inside
需要的 Tab导航能力。
它被设计为以这种方式使用。
Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
关于iphone - 内部有 3 个选项卡且没有工作标题的导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8637810/