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

时间:2011-10-02 23:11:03

标签: iphone cocoa-touch uinavigationcontroller

以下是代码:

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

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

2 个答案:

答案 0 :(得分:1)

这里有两件事看起来有点奇怪......希望修复它们会让后面的btn显示出来:

    - (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中是否已正确连接所有内容(如果有的话)。祝你好运!

答案 1 :(得分:0)

使用您的代码,它仍然会推送到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";