How can I Invoke tableview cell click event out of tableview frame?

100 Views Asked by At

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

1

There are 1 best solutions below

2
On

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.