The default NavigationController template offered by apple, it has one navigationController and a table.
And if you select a cell, a new view will be pushed into navigationController and if you pop the view, the selected cell will be de-hightlighted automatically.
But how does table know when to de-hightlight it and how does it know which cell is selected??
or does it just re-load all data again?
how does table know when to de-hightlight it
You can deselect your cell right in selection handler:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath: indexPath];
...
}
or reset selection in controller's -viewWillAppear:
method
and how does it know which cell is selected?
UITableView has the following method to get selected row indexPath:
- (NSIndexPath *)indexPathForSelectedRow
For Swift 3.0
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
if self.yourTableView.indexPathForSelectedRow != nil
{
self.yourTableView.deselectRow(at: self.yourTableView.indexPathForSelectedRow!, animated: true)
}
}
This code will avoid the Crash as well...
Also, add the below line in the other ViewController whom you're pushing while selecting a TableViewCell.
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
Works like a Charm =]
Hope it helps..