Vyachaslav Gerchicov
Vyachaslav Gerchicov

Reputation: 2457

iOS store selection for UITableViewCell?

for example native iOS apps Mail and Notes:

1)if you select a cell - the app pushes view controller

2)if you click back button after step 1 - the app pops view controller and you see that this cell is selected and becomes deselected with animation

How to implement the same behaviour? Currently I need to add it to each table in my app.

Upvotes: 0

Views: 102

Answers (2)

InsertWittyName
InsertWittyName

Reputation: 3940

I assume you're using a UITableView within a UIViewController (and not a UITableViewController, which has the behaviour you mention by default).

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if let selectedIndexPath = tableView.indexPathForSelectedRow {
        tableView.deselectRow(at: selectedIndexPath, animated: true)
    }
}

Upvotes: 1

LastMove
LastMove

Reputation: 2482

Actually It the default behaviour of UITableViewController. If you are using UITableViewController just check this box in your storyboard : clear on appearance

If you are not using UITableViewController, in your viewDidAppear (so the user can see it, just unselect the selected cell.

Upvotes: 1

Related Questions