开发者

UINavigationController UIBarButtonItem not responding to action method

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 meth开发者_如何学Pythonod:

-

(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


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜