How to get UITableViewCell indexPath from the Cell?

后端 未结 11 1610
野趣味
野趣味 2020-12-07 20:11

How do I, from a cell, get its indexPath in a UITableView?

I\'ve searched around stack overflow and google, but all the information is on t

11条回答
  •  春和景丽
    2020-12-07 20:21

    On iOS 11.0, you can use UITableView.indexPathForRow(at point: CGPoint) -> IndexPath?:

    if let indexPath = tableView.indexPathForRow(at: cell.center) {
        tableView.selectRow
        (at: indexPath, animated: true, scrollPosition: .middle)
    }
    

    It gets the center point of the cell and then the tableView returns the indexPath corresponding to that point.

提交回复
热议问题