且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UITableView didSelectRow 返回错误的行索引值

更新时间:2023-02-06 22:56:51

检查你的委托名称不是 didDeselectRowAt 它是 didSelectRowAt

check your delegate name is not didDeselectRowAt it is didSelectRowAt

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)


    let alertController = UIAlertController(title: "Hint", message: "You have selected row \(indexPath.row).", preferredStyle: .alert)
    let alertAction = UIAlertAction(title: "Ok", style: .cancel, handler: nil)
    alertController.addAction(alertAction)
    present(alertController, animated: true, completion: nil)
}

按照你的代码,我创建了示例项目

as per your code follow I created the sample project