Gerd Castan
Gerd Castan

Reputation: 6849

Override setEdit in UITableViewController: where does the call come from?

When the user taps on Edit or Done in the top left corner of a UITableViewController, I need to change some things (in addition to what Apple does automatically).

I override setEditing(), do my visual changes there. Works fine.

The method setEditing() of the UITableViewController is also called, when the user swipes left on a UITableViewCell.

Here comes the problem: like Apple, I need to do important things differently, when a user swipes left on a cell.

How do I know which user action (tapping on edit or swiping left on a cell) caused the setEditing() call?

Upvotes: 1

Views: 290

Answers (2)

Gerd Castan
Gerd Castan

Reputation: 6849

Inspired by trying @bbarnhart's answer:

When overriding tableView(_:willBeginEditingRowAt:) then setEditing(true) is not called at the begin of a cell swipe.

When overriding tableView(_:didEndEditingRowAt:) then setEditing(false) is not called at the end of the cell editing.

So just the presence of these overrides solves the problem.

Upvotes: 1

bbarnhart
bbarnhart

Reputation: 6710

To tell if a swipe caused editing to occur, add the UITableViewDelegate callback tableView(_:willBeginEditingRowAt:) to your code. Set an internal flag in this function and when setEditing is called check this flag.

Upvotes: 1

Related Questions