0

I'm using a UITableView and a custom cell.when i click one cell it goes to the back screen and i save the indexPath in a NSIndexpath ; when again i navigate to tableView i change backgroundColor of the previously selected cell so user can Identify selection.

 if (!self.indexvalue<0) {

    [[self.CountryCodeTableView cellForRowAtIndexPath:self.indexvalue] setBackgroundColor:[UIColor blueColor]];


}

but when the cell is reused then it gets same indexPath for many cells. Can you please tell me how to solve it. How will i identify when the cell is reused.

Thank you so much!

Parinita
  • 87
  • 2
  • 13

1 Answers1

0

On navigating back to previous view controller, you can use following method to identify earlier selected cell - indexPathForSelectedRow.

so you can use -

if (!self.indexvalue<0) {
    NSIndexPath *selectedRowIndexPath = [self.CountryCodeTableView indexPathForSelectedRow];
    [[self.CountryCodeTableView cellForRowAtIndexPath: selectedRowIndexPath] setBackgroundColor:[UIColor blueColor]];
}
rishi
  • 11,779
  • 4
  • 40
  • 59