Martin Perry
Martin Perry

Reputation: 9527

Swift - change table cell background in edit mode

I have table with user defined cells via XIB. My table supports edit mode to delete or rearange cells.

I have implemented

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}

Now, is there a way, how to change background of cells, while they are being in "edit mode"?

Upvotes: 1

Views: 705

Answers (1)

Sweeper
Sweeper

Reputation: 274358

I think you need two delegate methods for this:

func tableView(UITableView, willBeginEditingRowAt: IndexPath)

Tells the delegate that the table view is about to go into editing mode.

And

func tableView(UITableView, didEndEditingRowAt: IndexPath?)

Tells the delegate that the table view has left editing mode.

You can implement each delegate method like this:

tableView.cellForRow(at: indexPath).backgroundColor = someColor

Upvotes: 2

Related Questions