当表格单元格中包含可滑动元素时,可能会出现无法滑动单元格的问题。此时,可以使用以下代码解决该问题:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MyTableViewCell
// 添加下面这行代码
cell.contentView.superview?.isUserInteractionEnabled = true
// 设置cell属性
return cell
}
将代码添加到单元格的cellForRowAt
方法中,在返回单元格之前,为单元格的父视图启用交互性。这将允许用户在单元格中滑动可滑动元素而不是滑动整个单元格。