0

我有一个带有根视图控制器和子视图控制器的导航应用程序。在儿童-didSelectRowAtIndexPath方法中,我添加一个带有目标 /动作的后退按钮,如下所示:选择后按钮时,我想返回root视图,而不是(以前的)儿童视图。但是,我无法弄清楚为什么 action 方法没有触发:

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    Question *newQuestion = [[Question alloc]
                           initWithNibName:@"Question"
                           bundle:nil];
    newQuestion.testQuestion =  self.testQuestion;
    [self.navigationController dismissModalViewControllerAnimated:YES]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                    initWithTitle:@"Quiz" 
                    style:UIBarButtonItemStylePlain 
                    target:self 
                    action:@selector(backToMenu)];

    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];
    [self.navigationController pushViewController:newQuestion
                                         animated:YES];
    [newQuestion release];
}

在我的 Question 类的顶部,我包含了 backToMenu 方法:

-

(void)backToMenu {
    NSLog(@" backToMenu");
     [self.navigationController popViewControllerAnimated:YES];

但是,-backToMenu永远不会被解雇;我从来没有看过NSLog显示器。我-viewWillAppear被触发了,但我不知道如何判断我是否因为按下后退按钮或选择了表格行而在那里。对你来说可能很明显,但我很难过......谢谢

4

1 回答 1

0

你为什么不把你的后退按钮放在屏幕上,你希望它显示我假设的“问题”屏幕和“backToMenu”方法,你可以使用

[self.navigationController popToRootViewControllerAnimated:YES];
于 2011-05-12T01:04:06.793 回答