UITableViewCell 不响应响应者链

Posted

技术标签:

【中文标题】UITableViewCell 不响应响应者链【英文标题】:UITableViewCell Does not respond to the responder chain 【发布时间】:2013-11-27 07:04:50 【问题描述】:

我在开发过程中遇到了一个问题,我有一个UITableViewCell,它添加了一个UIButtonUIButton已经满了Cell),希望我的UIButton响应我的touchupinside事件,经过处理完成后,事件再次发送,直到单元响应didSelectRowAtIndexPath方法。但是现在,didSelectRowAtIndexPath没有工作? (注:我不想手动调用didSelectRowAtIndexPath方法,希望通过响应者链来解决这个问题)

【问题讨论】:

按钮操作正常,但没有调用 selectrow 对吗? 【参考方案1】:

如果按钮小于单元格,它应该按预期工作:如果您触摸按钮,按钮处理程序将触发,如果您触摸单元格中的另一个区域,didSelectRowAtIndexPath 将触发。

但是,如果按钮覆盖整个单元格,这不是问题。您可以从按钮处理程序调用与表视图委托相同的例程。

- (void)tableView:(UITableView *)tableView 
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
   [self doCellThingWithIndexPath:indexPath];


- (void)buttonAction:(UIButton*)sender 
    // do whatever the button does, then
    CGRect buttonFrame = [button convertRect:sender.bounds toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView 
                              indexPathForRowAtPoint:buttonFrame.origin];
    [self doCellThingWithIndexPath:indexPath];

【讨论】:

以上是关于UITableViewCell 不响应响应者链的主要内容,如果未能解决你的问题,请参考以下文章

iOS 事件响应者链的学习(也有叫 UI连锁链)

UITableViewCell 变得无响应

UI事件传递和响应

使 UIWebView 成为 UITableviewCell 的一部分

根据内容可用性调整 UITableViewCell 的大小作为响应

用作自定义 UITableViewCell 的 XIB 中的自定义按钮不响应点击(ios7)