UITableView disable swipe to delete, but still have delete in Edit mode?

后端 未结 7 1918
面向向阳花
面向向阳花 2020-12-07 10:33

I want something similar as the Alarm app, where you can\'t swipe delete the row, but you can still delete the row in Edit mode.

When commented out tableView:commitE

相关标签:
7条回答
  • 2020-12-07 11:06

    You need to implement the CanEditRowAt function.

    You can return .delete in the EditingStyleForRowAt function so you can still delete in editing mode.

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        if tableView.isEditing {
            return true
        }
        return false
    }
    
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
        return .delete
    }
    
    0 讨论(0)
提交回复
热议问题