Reputation: 2457
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
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
Reputation: 2482
Actually It the default behaviour of UITableViewController.
If you are using UITableViewController just check this box in your storyboard :
If you are not using UITableViewController, in your viewDidAppear (so the user can see it, just unselect the selected cell.
Upvotes: 1