如何找出选择了哪两个自定义单元格?

时间:2018-02-06 07:13:03

标签: ios swift delegates tableview

我的tableview中有两种类型的自定义单元格,我想知道当用户点击特定行时选择了哪种类型的单元格。我应该在UITableView的didSelect委托中写什么?

1 个答案:

答案 0 :(得分:0)

如果有两个自定义单元格,则必须有两个UITableViewCell类,您可以根据它简单地区分单元格。 请参阅以下代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if let cell = tableView.cellForRow(at: indexPath) as? MyCustomCell1 {
        //Perform action here
    } else if let cell = tableView.cellForRow(at: indexPath) as? MyCustomCell2 {
        //Perform action here
    }
}