UINavigationController & UITabBarController


#1

Hi,
I have some troubles to understand this concept. :slight_smile:

I need to use a UINavigationController and a UITabBarController for my App.
I think I have some confusions about the Controller notions.

By reading the chapter 7, I have no problem to add my TabBarItems.
But how can I have in the same time a navigation Item?

This is what I did.

From the appDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	tabBarController = [[UITabBarController alloc] init];
	UIViewController *vc1 =[[RechercheViewController alloc] init];
	NSArray *viewControllers =[NSArray arrayWithObjects:vc1,nil];
	[vc1 release];
	[tabBarController setViewControllers:viewControllers];
	UINavigationController *navController =[[UINavigationController alloc] initWithRootViewController:tabBarController];
	[window addSubview:[navController view]];
        [window makeKeyAndVisible];
	return YES;
}

I get my TabBar as well as my Navigation bar. I don’t know if it’s the good way.
Then, from my viewController,
I wrote this, but the title is not displayed on the NavigationItem.

-(id)init
{
	[super initWithNibName:nil bundle:nil];
	UITabBarItem *tbi =[self tabBarItem];
	[tbi setTitle:@"Search"];
	[[self navigationItem] setTitle:@"Search"];
	return self;
}

-(id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
	return [self init];
}
- (void)viewDidLoad {
    [super viewDidLoad];
  
}

Do I miss something?

Stan


#2

You are setting the title of the tabBarItem. This title will only be displayed when this view controller is part of a tab bar controller. Here, this view controller is part of a navigation controller. Therefore, if you wish to display a title for this view controller, you must set the title of the view controller’s navigationItem.


#3

I’m really lost…
Everything works well without the TabBarController.
I get my navigation bar.

But I have no clue how to set in same time the TabBarController.
When I set it, my “child” views lost all their functions.
I mean, I have a tableView that holds child TableViews.
Without the TabBarController, when I tap onto a row, I get the tableView child.
With the TabBarController, it doesn’t work.
I will try to read again :slight_smile:


#4

Do you want a tab bar controller that has navigation controllers inside it?

Make a tab bar controller.
Make a table view controller.
Make a navigation controller whose rootViewController is the table view controller.
Add the navigation controller to the tab bar controllers viewControllers.
Add a tab bar controller’s view to the window.