TIMEX
TIMEX

Reputation: 271624

In my UITableView, how can I reset the "selected cell color" back to default upon selection?

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    checkRequirements() { () -> Void in
        var room = self.rooms[indexPath.row]
        self.roomForPreview = room
        self.indexPathForPreview = indexPath
        self.performSegueWithIdentifier(CONSTANTS.SegueLobbyToRoomPreview, sender: self.view)
    }
}

I perform a segue when a user selects a cell, but when I unwind, I find that the cell still has a grey background.

How can I make the cell grey only on touch? Once the touch is gone, the cell goes back to normal color.

Upvotes: 1

Views: 759

Answers (1)

Glorfindel
Glorfindel

Reputation: 22631

Use deselectRowAtIndexPath:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
    ...

If you're using a UITableViewController, you can set the clearsSelectionOnViewWillAppear property to true - this will work as well.

Upvotes: 5

Related Questions