【问题标题】:Navigation Items in UITableViewController are not appearing?UITableViewController 中的导航项没有出现?
【发布时间】:2010-06-16 02:08:01
【问题描述】:

我正在以模态方式呈现的 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];
}

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

- (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 内部时,它不会出现,但是当我推送视图本身时,我能够看到它。

我错过了什么?

【问题讨论】:

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


    【解决方案1】:

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

    除了在主屏幕上之外,我从未将 tabBar 用于任何东西,但您的代码可能如下所示:

    在 arTabBarController.selectedViewController = arViewController;之后

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

    就像我说的,我还没有用 tabBar 做过,但我很确定它会是这样的

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 该死的,错过了 6 秒 :(
      【解决方案3】:

      有一个简单的解决办法,put setting in view会出现

      -(void)viewWillAppear:(BOOL)animated
      {
          [super viewWillAppear:animated];
      
          [self.navigationController setNavigationBarHidden:NO animated:animated];
      }
      

      希望对新手有所帮助;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-30
        • 1970-01-01
        • 2016-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多