我有一个带有根视图控制器和子视图控制器的导航应用程序。在儿童-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
被触发了,但我不知道如何判断我是否因为按下后退按钮或选择了表格行而在那里。对你来说可能很明显,但我很难过......谢谢