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

回答

0

你爲什麼不把U上希望它顯示我承擔的「問題」屏幕和「backToMenu」方法screnn後退按鈕,你可以使用

+0

那麼,我不希望後退按鈕回到堆棧上的先前視圖,我不想後退按鈕來清除堆棧並從根部加載。你的建議是另一個導航欄按鈕項目? – Namhcir 2011-05-12 01:20:24