0

I have a navigation app with a root viewcontroller and a child viewcontroller. In the child -didSelectRowAtIndexPath method, I add a back button with a target / action as follows: When the back button is selected, I want to go back to root view, rather than the (previous) child view. However, I can't figure out why the action method isn't firing:

- (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];
}

At the top of my Question class, I include the backToMenu method:

-

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

However, -backToMenu is never being fired; I never see the NSLog display. My -viewWillAppear gets triggered, but I don't know how to tell whether I'm there because of the back button being pressed or the table row being selected. Probably obvious to you, but I'm stumped...thx

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
Namhcir
  • 825
  • 3
  • 9
  • 16

1 Answers1

0

Why dont you put your back button on the screnn u want it to display which I assumed the 'Question' screen and in the 'backToMenu' method, u can use

[self.navigationController popToRootViewControllerAnimated:YES];
sicKo
  • 1,241
  • 1
  • 12
  • 35
  • Well, I don't want the backbutton to go back to the prior view on the stack, I wan't the back button to clear the stack and load from the root. Would your suggestion be another navigation bar button item? – Namhcir May 12 '11 at 01:20