-3

I want deselect a row previously selected selecting this again. I only can deselected this row clicking in other row but I want deselect this clicking on this again. How can I do this?

This is my code:

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

 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
 {
[self updateTableView];
}


 - (void)updateTableView
{
[self.tableView beginUpdates];
[self.tableView endUpdates];
}

Thanks!!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3745888
  • 6,143
  • 15
  • 48
  • 97
  • please check before posting a question if something related is present or not. http://stackoverflow.com/questions/3968037/how-to-deselect-a-selected-uitableview-cell – Er. Khatri Aug 23 '16 at 18:20

2 Answers2

0

There is a deselectRowAtIndexPath method in the tableviews. Use that method passing your indexpath.

Ruchira Randana
  • 4,021
  • 1
  • 27
  • 24
0

Track the selected index path using a property. Within tableView:didSelectRowAtIndexPath: compare your stored index path to the index path provided in the delegate method. If they are the same, it means the row was already selected. Call deselectRowAtIndexPath:animated: to deselect it and set your stored index path to nil. Otherwise, update the stored index path to the index path provided in the delegate method.

willbur1984
  • 1,418
  • 1
  • 12
  • 21