提问者:小点点

UITableView:如何在滑动表格视图单元格时停止选择


我有滑动删除代码在这里和它我的自定义TableViewCell我已经实现了setSelected方法如下。。。

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
       // tableView.allowsSelectionDuringEditing = false
        if tableView.indexPathForSelectedRow != nil, tableView.indexPathForSelectedRow == indexPath {
            return UITableViewCell.EditingStyle.none
        }
        return UITableViewCell.EditingStyle.delete
    }
override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        //some code here 
}

逻辑将根据选择执行tableview展开折叠。。但是这里的问题是如果我滑动删除setSelected也会触发。。 不知道怎样才能阻止任何帮助得到感激。


共1个答案

匿名用户

在cellForRow中试试这个

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell_identifier", for: indexPath)                
    cell.selectionStyle = UITableViewCell.SelectionStyle.none
    //or this based on swift version 
    cell.selectionStyle = .none
    return cell