简体   繁体   English

具有NavigationBar的TabBarController

[英]TabBarController with NavigationBar

I am writing an app that uses the UITabBarController at the bottom. 我正在编写一个在底部使用UITabBarController的应用程序。

Hierarchy 层次结构

- Page 1
- - SubPage 1
- - SubPage 2
- - SubPage 3
- Page 2
- Page 3

Page 1 contains a grid with multiple items, when selected the choosen subpage will be displayed. 页面1包含一个包含多个项目的网格,选中后将显示所选的子页面。
On the sub pages I replace the Tabs of the TabBarController with all the subpages and want display a back link in the Navigation Bar. 在子页面上,我用所有子页面替换TabBarController的Tabs,并希望在导航栏中显示反向链接。

I create the tabBar programmatically. 我以编程方式创建tabBar。
At the moment I init the navigationController with the tabBarController as rootViewController. 目前,我以tabBarController作为rootViewController初始化了NavigationController。
That seems to work, but I cant change anything on the NavigationBar, setting the title has no effect, buttons dont appear. 这似乎可行,但我无法在NavigationBar上进行任何更改,设置标题无效,按钮不出现。

What I'm doing wrong? 我做错了什么? Or is there a better way achieving what I want? 还是有更好的方法实现我想要的?

I target iOS5 with ARC (iPad only) 我将iOS5与ARC作为目标(仅限iPad)

You set the title of the parent navigation controller by setting the title of the child. 您可以通过设置子标题来设置父导航控制器的标题。 You'd need to set the title of the tabbar-controller: 您需要设置标签栏控制器的标题:

myTabBarController.title = @"Page 1";

You also set the buttons of the navigationbar inside the child-view, as the contents of the bar depend on the current visible view: 您还设置了子视图内导航栏的按钮,因为栏的内容取决于当前的可见视图:

UIBarButtonItem *myItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(myBackAction:)];
myTabBarController.navigationItem.leftBarButtonItem = myItem;

Remember that changing the contents of the tabbar after tapping an item on it is considered bad user experience. 请记住,点击选项卡后更改选项卡的内容被认为是不良的用户体验。 There are probably other, better ways to achieve the same effect. 可能还有其他更好的方法可以达到相同的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM