topgun
topgun

Reputation: 2573

Enable Reorder Control in UITableView as default without being in edit mode

I am currently working on a solution where I need to have a UITableView by default in reorder mode without having a delete button but could enable the delete button when necessary. I am just curious if this is even achievable in iOS? If so what should be my approach for this?

Upvotes: 0

Views: 185

Answers (1)

Costea Bogdan
Costea Bogdan

Reputation: 146

In my opinion your table view should always be in edit mode.

To make the reorder controls appear you should implement UITableViewDataSource methods

tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool

and

tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)

If you don't want the delete button to be displayed you can do that by implementing

tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle

and return .none by default or .delete when you want to have the button displayed.

Upvotes: 1

Related Questions