【发布时间】:2011-05-12 00:39:35
【问题描述】:
我有一个带有根视图控制器和子视图控制器的导航应用程序。在子-didSelectRowAtIndexPath 方法中,我添加了一个带有目标/操作的后退按钮,如下所示:
选择后退按钮后,我想返回根视图,而不是(上一个)子视图。但是,我不知道为什么 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 被触发,但由于按下后退按钮或选择了表格行,我不知道如何判断我是否在那里。
对你来说可能很明显,但我很难过......谢谢
【问题讨论】:
标签: uinavigationcontroller uibarbuttonitem popviewcontroller