views:

25

answers:

1

I know that this has been discussed several times in many other topics, blogs, book, youtube, etc. But, let me explain my case. I want so that when an application opens up, it shows a facebook connect button to login. After the user login, then it will bring up the tabBarView. In my app delegate I first add the MainViewController and there I had shown the facebook connect login button. Then after it's logged in it adds the tabBarViewController as it's sub view.

Now inside this tabBarViewController I want so that it has 2 tabs. The first tab people and second is map. I want to add a navBar in the people tab. So what I did in my code was the following:

tabBarViewController = [[TabBarViewController alloc] init];
    mvc = [[MapViewController alloc] init];
    UIImage* mapIcon = [UIImage imageNamed:@"13-target.png"];
    mvc.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Map" image:mapIcon tag:0] autorelease];

    tvc = [[TableViewController alloc] init];
    UIImage* peopleIcon = [UIImage imageNamed:@"112-group.png"];
    tvc.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"People" image:peopleIcon tag:0] autorelease];

    friendsNavController = [[FriendsNavController alloc] init];


    tabBarViewController.viewControllers = [NSArray arrayWithObjects: friendsNavController, tvc, mvc, nil];
    tvc.userInfo = _userInfo;
    [self.tabBarViewController viewWillAppear:YES];
    [self.view addSubview:self.tabBarViewController.view];

The result now is that I have 3 tab bar, one with a nav bar, one with a table list, and one is the map. How can I change the code so that the nav bar and the table view are in one tab bar? What am I doing wrong here?

Here's how it looks on interface builder:

alt text

+1  A: 

The tab bar controller's view controllers should only consist of the navigation controller and the mapViewController.

The TableViewController (tvc) will be in the navigation controller's viewControllers, not in the tabBarViewController's. Call initWithRootViewController:tvc on the friendsNavController

So your array should only have 2 items (friendsNavController and mvc) for the tabBarViewControllers.

Also, this would mean that the navigationController has a tabBar item instead of the tableViewController.

Jbonniwell
I am still confused on where should I call the initWithRootViewController at?
EquinoX
in your code sample above you call:friendsNavController = [[FriendsNavController alloc] init];Try:friendsNavController = [[FriendsNavController alloc] initWithRootViewController:tvc];
Jbonniwell
what things do I need to put in the navcontroller?
EquinoX
That line with initWithRootViewController: should be all you need for it to function, you can look at the class reference for UINavigationController in the documentation for other things to customize.
Jbonniwell