0
我有一个导航应用程序,包含一个根视图控制器和一个子视图控制器。在child -didSelectRowAtIndexPath方法中,我添加一个带有目标/动作的后退按钮,如下所示: 当选择后退按钮时,我想返回到根视图,而不是(之前的)子视图。不过,我想不通为什么action方法在不触发:UINavigationController UIBarButtonItem没有响应动作方法
- (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];
}
我的问题类的顶部,我包括backToMenu方法:
-
(void)backToMenu {
NSLog(@" backToMenu");
[self.navigationController popViewControllerAnimated:YES];
然而,-backToMenu从未被解雇;我从来没有看到NSLog显示。 我的-viewWillAppear被触发,但我不知道如何判断我是否在那里,因为后退按钮被按下或表格行被选中。 对你来说可能很明显,但我难倒... THX
那么,我不希望后退按钮回到堆栈上的先前视图,我不想后退按钮来清除堆栈并从根部加载。你的建议是另一个导航栏按钮项目? – Namhcir 2011-05-12 01:20:24