【问题标题】:UINavigationController UIBarButtonItem not responding to action methodUINavigationController UIBarButtonItem 没有响应操作方法
【发布时间】: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


    【解决方案1】:

    你为什么不把你的后退按钮放在屏幕上,你希望它显示我假设的“问题”屏幕和“backToMenu”方法,你可以使用

    [self.navigationController popToRootViewControllerAnimated:YES];
    

    【讨论】:

    • 好吧,我不希望后退按钮返回堆栈上的先前视图,我不希望后退按钮清除堆栈并从根加载。您的建议是另一个导航栏按钮项吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    相关资源
    最近更新 更多