Deselect the selected cell when the navigationController pops up?

The default NavigationController template offered by apple contains one navigation controller and a table.

And if you select a cell, the new view will be clicked in the navigationController, and if you place the view, the selected cell will be automatically disabled.

But how do you know the table, when do you need to remove it, and how do you know which cell is selected?

or is he just reloading all the data again?

+1
source share
2 answers

How to find out the table, when you need to remove it from the site

You can deselect your cell directly in the selection handler:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath: indexPath]; ... } 

or reset in the -viewWillAppear: controller -viewWillAppear: method

and how does he know which cell is selected?

UITableView has the following method for getting the selected indexPath row:

 - (NSIndexPath *)indexPathForSelectedRow 
+6
source

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 Failure as well ...

Also, add the following line to another ViewController that you click when you select TableViewCell.

 self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true 

Works like a Charm =]

Hope this helps.

0
source

All Articles