0

Is there a way when I touch the point which out of tableview frame,invoke tableview delegate function -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath?

I've tried override superview of tableview's -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event and change the point and let the event continue pass to the tableview and tableview's subviews.Just scroll event work but click event.

Here is a demo project

cs Kim
  • 1

1 Answers1

0

Problem is what UITableView don't keep all cells alive. Cells are reusable. Just several cells before and after visible area placed on view. Try to call the delegate method directly.

tableView.delegate?.tableView?(tableView, didSelectRowAt: indexPath)

If you want to call this method only for cells currently available on a table view.

     if let _ =  tableView.cellForRow(at: indexPath) {
        tableView.delegate?.tableView?(tableView, didSelectRowAt: indexPath)
    }

You could easily convert the screen position into the index of the cell.

  • It's a good solution,but i think it`s not a best one. it's out of tableview's control.is there another way? – cs Kim Mar 22 '19 at 00:52
  • You should understand not all cells placed on the table. Only visible and some before and after visible area. So you could tap only on these cells. For remaining cells only this way is possible. – Vladimir Konon Mar 22 '19 at 06:03