[英]UITableViewCell Does not respond to the responder chain
I encountered a problem during the development, I have a UITableViewCell
, it adds a UIButton
( UIButton
was full of the Cell), I hope my UIButton
response my touchupinside
event, after processing is completed, the events send up again, until the Cell to response didSelectRowAtIndexPath
method.but now, didSelectRowAtIndexPath
didn't work? 我在开发过程中遇到问题,我有一个
UITableViewCell
,它添加了一个UIButton
( UIButton
充满了Cell),希望我的UIButton
响应我的touchupinside
事件,在处理完成后,该事件再次发送touchupinside
,直到Cell到响应didSelectRowAtIndexPath
方法。但是现在, didSelectRowAtIndexPath
没有起作用吗? (note: I don't want to manually call didSelectRowAtIndexPath
method, I hope that through the responder chain to solve this problem) (注:我不想手动调用
didSelectRowAtIndexPath
方法,希望通过响应者链来解决这个问题)
If the button is smaller than the cell, it should work as expected: if you touch the button, the button handler fires, if you touch another area in the cell, didSelectRowAtIndexPath
fires. 如果按钮比单元格小,它将按预期工作:如果触摸按钮,则按钮处理程序将触发,如果触摸单元格中的另一个区域,则
didSelectRowAtIndexPath
触发。
If, however, the button covers the entire cell, this is a non-issue. 但是,如果按钮覆盖整个单元格,则不是问题。 You can call the same routine from the button handler as from the table view delegate.
您可以从按钮处理程序调用与表视图委托相同的例程。
- (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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.