About UITableView Delete Button Disabled

Asked 2 years ago, Updated 2 years ago, 117 views

If you implement edit mode in UITableView, you can delete it by swiping from right to left without pressing the Edit button.
I want to make it possible to delete it only when I press edit mode.

In short, I want to make it impossible to delete it by swiping from right to left.
Is there a way?
I looked it up, but I couldn't find a specific way.

You can edit (delete) without pressing the edit button
I think it's strange...

Please use Swift3.

swift3 uitableview

2022-09-30 11:22

1 Answers

Override tableView(_:editingStyleForRowAt:) in UITableViewDelegate to change the value returned, depending on the condition.

To display the delete button only when the table view is in edit mode and nothing appears when swiping sideways, check the tableView.isEditing property, return .delete in edit mode, or return .none.

override functableView(_tableView:UITableView, editingStyleForRowAtindexPath:IndexPath)->UITableViewCellEditingStyle{
    iftableView.isEditing{
        return.delete
    }
    return.none
}

This method allows you to customize the cell editing style for each row.Otherwise, it is interpreted as .delete by default.Therefore, if you do nothing, the Delete button will appear when you are in edit mode or swipe.


2022-09-30 11:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.