我的tableview中有两种类型的自定义单元格,我想知道当用户点击特定行时选择了哪种类型的单元格。我应该在UITableView的didSelect委托中写什么?
答案 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
}
}