views:

33

answers:

2

I am displaying a UITableViewController inside of a UITabBarController that is being presented modally:

-(IBAction)arButtonClicked:(id)sender{

   //this is a uitableviewcontroller
    ARViewController* arViewController = [[[ARViewController alloc] initWithNibName:@"ARViewController" bundle:nil]autorelease];

    LeaderBoardTableViewController* lbViewController = [[[LeaderBoardTableViewController alloc] initWithNibName:@"LeaderBoardTableViewController" bundle:nil]autorelease];
    lbViewController.title = @"Leaderboard";

    arTabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
    arTabBarController.viewControllers = [NSArray arrayWithObjects:arViewController, lbViewController, nil];
    arTabBarController.selectedViewController = arViewController;

    [self presentModalViewController:arTabBarController animated:YES];
}

In my viewDidLoad for arViewController method I am setting the navigation items:

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    self.clearsSelectionOnViewWillAppear = NO;
    self.title = @"AR";

    leaderBoardButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize 
                                                                  target:self 
                                                                  action:@selector(leaderBoardButtonClicked:)];

    self.navigationItem.rightBarButtonItem = leaderBoardButton;

}

My navigation bar doesn't appear when it is inside of the UITabBarController, but when I push the view itself I am able to see it.

What am I missing?

A: 

I needed to add a UINavigationBar:

ARViewController* arViewController = [[[ARViewController alloc] initWithNibName:@"ARViewController" bundle:nil]autorelease];
    UINavigationController *arNavController = [[UINavigationController alloc] initWithRootViewController:arViewController];

    LeaderBoardTableViewController* lbViewController = [[[LeaderBoardTableViewController alloc] initWithNibName:@"LeaderBoardTableViewController" bundle:nil]autorelease];
    lbViewController.title = @"Leaderboard";    
    UINavigationController *lbNavController = [[UINavigationController alloc] initWithRootViewController:lbViewController];

    arTabBarController = [[UITabBarController alloc] init];//initWithNibName:nil bundle:nil];
    arTabBarController.viewControllers = [NSArray arrayWithObjects:arNavController, lbNavController, nil];
    arTabBarController.selectedViewController = arNavController;

    [self presentModalViewController:arTabBarController animated:YES];
Sheehan Alam
dammut, missed by 6 seconds :(
Rudiger
+1  A: 

Heh, I've been stumped by this too. What you need to do is send the rootViewController.

I've never used a tabBar for anything except on the main screen but ur code will probably look like this:

after arTabBarController.selectedViewController = arViewController;

UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController: arTabBarController] autorelease];
[self presentModalViewController: navController animated:YES];

Like I said I haven't done it with a tabBar but I'm pretty sure it will be something along these lines

Rudiger