UITableViewController中的导航项目没有出现?

时间:2010-06-16 02:08:02

标签: iphone objective-c cocoa-touch uitableview uitabbarcontroller

我正在以模态方式呈现的UITabBarController中显示一个UITableViewController:

-(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];
}

在我的viewDidLoad for arViewController方法中,我正在设置导航项:

- (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;

}

我的导航栏在UITabBarController内部时不会出现,但是当我推动视图本身时,我能够看到它。

我错过了什么?

3 个答案:

答案 0 :(得分:2)

嘿,我也被这个难过了。你需要做的是发送rootViewController。

我从来没有在主屏幕上使用过tabBar,但你的代码可能看起来像这样:

在arTabBarController.selectedViewController = arViewController;

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

就像我说的那样,我没有用tabBar完成它,但我很确定它会是这些行的东西

答案 1 :(得分:0)

我需要添加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];

答案 2 :(得分:0)

有一个简单的解决方案,将在视图中显示设置

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

希望它可以帮助一些新手;

相关问题