我想使tableView的单元格不可选择,但仍允许滚动。当我放置
tableView.isUserInteractionEnabled = false
在viewDidLoad
中的某些答案中建议使用
,它既可以防止选择,又可以防止滚动。
添加:
cell.selectionStyle = .none
在以下cellforrowatindexpath
中对我没有任何作用。
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
self.tableView.beginUpdates()
self.tableView.endUpdates()
if let cell = tableView.dequeueReusableCell(withIdentifier: "myMessageCell", for: indexPath) as? myMessageCell {
cell.message = messages[indexPath.row]
cell.selectionStyle = .none
}
return tableView.dequeueReusableCell(withIdentifier: "myMessageCell", for: indexPath)
}
有人可以建议如何在不阻止滚动的情况下阻止选择吗?
预先感谢您的任何建议。
答案 0 :(得分:1)
希望您正在寻找这个:
tableView.allowsSelection = false
答案 1 :(得分:1)
问题在于您没有返回要出队的相同单元格。取而代之的是,您使另一个单元出列并返回它没有设置的任何属性。
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "myMessageCell", for: indexPath) as? myMessageCell {
cell.message = messages[indexPath.row]
cell.selectionStyle = .none
return cell // Return the cell here instead
}
// return tableView.dequeueReusableCell(withIdentifier: "myMessageCell", for: indexPath) // Return another cell which has none of your properties set.
return UITableViewCell() // return default cell in case your cell is not dequeued
}