后栏未显示在导航控制器中

发布于 2024-12-08 04:41:42 字数 520 浏览 0 评论 0原文

这是代码:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];

    [self.navigationController pushViewController:detailViewController animated:YES];
    [self.navigationController popToRootViewControllerAnimated:YES];

    [DrinkDetailViewController release];
}

我想要一个后栏可以从详细视图转到我的根视图。我该怎么做?

Here is the code:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];

    [self.navigationController pushViewController:detailViewController animated:YES];
    [self.navigationController popToRootViewControllerAnimated:YES];

    [DrinkDetailViewController release];
}

I want to have a back bar to go to my root view from the detail view. How do I do it?

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

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

发布评论

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

评论(2

甜`诱少女 2024-12-15 04:41:42

这里有两件事看起来有点奇怪...希望修复它们将使后退按钮显示出来:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];

[self.navigationController pushViewController:detailViewController animated:YES];

//[self.navigationController popToRootViewControllerAnimated:YES]; <-- you just pushed a viewController onto the stack, and you're immediately removing it here and going to the root

[detailViewController release]; //<-- you want to release the *instance* that you created... not the Class
}

据我所知,UINavigationController 应该为您处理后退按钮。如果没有,我会检查您的 xib 中的所有内容是否正确连接(如果您有的话)。祝你好运!

There's 2 things that look a little weird here... hopefully fixing em will make the back btn show up:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];

[self.navigationController pushViewController:detailViewController animated:YES];

//[self.navigationController popToRootViewControllerAnimated:YES]; <-- you just pushed a viewController onto the stack, and you're immediately removing it here and going to the root

[detailViewController release]; //<-- you want to release the *instance* that you created... not the Class
}

The UINavigationController should take care of the back button for you as far as I know. If not, I would check to see that everything is wired up correctly in your xib (if you have one). Good Luck!

愿与i 2024-12-15 04:41:42

使用您的代码,它仍然会推送到 DrinkDetailViewController,但完全不需要 popToRootViewController。您应该删除如下行。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];

    [self.navigationController pushViewController:detailViewController animated:YES];

    [detailViewController release];
}

我相信,您的后退按钮没有显示在导航栏上的原因是因为您没有在根视图中放置任何标题。您可以将此代码放在根视图上的 viewdidload 方法上。

self.title = @"Your Title";

With your code, it will still push to the DrinkDetailViewController but the' popToRootViewController is totally unnecessary. You should delete the line like follows..

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:@"DrinkDetailViewController" bundle:nil];

    [self.navigationController pushViewController:detailViewController animated:YES];

    [detailViewController release];
}

And I believe, the reason your back button does not show up on the nav bar is because you didn't put any title in your root view. You can put this code on you viewdidload method on the root view.

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