UITableViewController 中的导航项没有出现?

发布于 2024-09-05 10:49:05 字数 1587 浏览 1 评论 0原文

我正在以模态方式呈现的 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 内部时,它不会出现,但当我推送视图本身时,它不会出现我能看到它。

我缺少什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清醇 2024-09-12 10:49:05

呵呵,我也被这个问题难住了。您需要做的就是发送 rootViewController。

除了在主屏幕上之外,我从未使用过 tabBar,但你的代码可能如下所示:

after arTabBarController.selectedViewController = arViewController;

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

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

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

放我走吧 2024-09-12 10:49:05

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

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];
计㈡愣 2024-09-12 10:49:05

有一个简单的解决方案,将设置放在视图中就会出现,

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

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

希望对新手有帮助;

There is a simple solution, put setting in view will appear

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

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

hope it help some newbies;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文