开发者

UITabBarController + UINavBarController

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开发者_Go百科"];
    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:

UITabBarController + UINavBarController


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜