Is there any way to hide - Delete button while editing UITableView
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When a UITableView enters editing mode, iOS shows a red minus button on each row by default, inviting the user to delete it. Sometimes you want editing mode active for reordering rows or for a custom UI, but you do not want the delete button to appear. Understanding the delegate methods that control editing style gives you precise, per-row control over which buttons appear and which stay hidden.
How UITableView Editing Mode Works
Calling tableView.setEditing(true, animated: true) puts the table into editing mode. In this state, iOS consults your data source and delegate to decide what each row should look like. The key decision is the editing style, which can be .delete (red minus), .insert (green plus), or .none (no button). If you do not implement the relevant delegate method, every row defaults to .delete.
Hiding the Delete Button with editingStyleForRowAt
The most direct way to hide the delete button is to return .none from the tableView(_:editingStyleForRowAt:) delegate method. This tells iOS that the row should not display any editing control.
With this in place, rows enter editing mode without showing the minus button. This is useful when you only need reordering handles.
Preventing Editing Entirely with canEditRowAt
If certain rows should not be editable at all, return false from tableView(_:canEditRowAt:). Unlike returning .none from the editing style method, this completely opts the row out of editing mode. The row will not indent, will not show any editing control, and will not respond to swipe-to-delete.
Conditional Editing Per Row
You can combine these methods to give each row a different behavior. For example, you might want the first section to be non-editable, the second section to show insert buttons, and the third section to be reorderable with no delete button.
When returning .none, you typically also implement tableView(_:moveRowAt:to:) so the user can reorder rows even though there is no delete or insert control.
Using the Insert Style Instead of Delete
Sometimes replacing delete with insert is the right choice. Returning .insert shows a green plus button instead of the red minus. This is common in screens where users pick items from a list to add them elsewhere.
Customizing Swipe Actions
Starting with iOS 11, you can fully customize the trailing and leading swipe actions using trailingSwipeActionsConfigurationForRowAt and leadingSwipeActionsConfigurationForRowAt. To disable the swipe-to-delete gesture while keeping editing mode, return a configuration with no actions.
You can also add custom actions like "Archive" or "Flag" instead of the default delete:
Preventing the Editing Indentation
Even with .none editing style, rows may still indent when entering editing mode. To prevent this, implement:
Common Pitfalls
- Forgetting to implement
editingStyleForRowAtand wondering why every row shows the delete button, since.deleteis the default. - Returning
.nonefromeditingStyleForRowAtbut not implementingcommit editingStyle, which can still allow swipe-to-delete on older iOS versions. - Confusing
canEditRowAt(opts out of editing entirely) witheditingStyleForRowAtreturning.none(enters editing mode without a button). - Not returning an empty
UISwipeActionsConfigurationwhen you want to disable swipe gestures, since returningniluses the default delete action. - Forgetting
shouldIndentWhileEditingRowAtwhen you want rows to stay visually unchanged in editing mode.
Summary
- Return
.nonefromtableView(_:editingStyleForRowAt:)to hide the delete button while keeping the row in editing mode. - Return
falsefromtableView(_:canEditRowAt:)to completely exclude a row from editing. - Use
.insertinstead of.deletewhen you need a green plus button for adding items. - Customize swipe behavior with
trailingSwipeActionsConfigurationForRowAtand return an empty configuration to disable swipe-to-delete. - Combine these delegate methods for fine-grained, per-row control over editing behavior.
Related reading
- Is there any way to see the file system on the iOS simulator?
- Is there anyway in Kotlin something like Dart's Completer behavior?
- Is there multiplatform lock in Kotlin?
- Is this a bug in Kotlin or I missing something?
- Is UIScreen mainScreen.bounds.size becoming orientation-dependent in iOS8?
- Iterating Through a Dictionary in Swift
- Java 7 language features with Android
- java.lang.ClassNotFoundException Didn't find class on path dexpathlist
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.