简体   繁体   中英

TabBarController with NavigationBar

I am writing an app that uses the UITabBarController at the bottom.

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.
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.

I create the tabBar programmatically.
At the moment I init the navigationController with the tabBarController as rootViewController.
That seems to work, but I cant change anything on the NavigationBar, setting the title has no effect, buttons dont appear.

What I'm doing wrong? Or is there a better way achieving what I want?

I target iOS5 with ARC (iPad only)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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