I try to reload one tableViewCell, but it scrolls to the top every time ... I do not add or remove cells, I just want to change the color of the selected cells.
This is what I do in cellForRowAtIndexPath:
SMPChoiceViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChoiceCell" forIndexPath:indexPath]; SMPChoice *choice = self.choices[indexPath.row - 1]; cell.choiceTextLabel.text = choice.text; if ([self.selectedChoices indexOfObject:choice] != NSNotFound) { cell.choiceTextLabel.textColor = [UIColor purpleColor]; } else { cell.choiceTextLabel.textColor = [UIColor blackColor]; }
And this is what I do in the didSelectRowAtIndexPath file
if ([self.selectedChoices indexOfObject:choice] != NSNotFound) { [self.selectedChoices removeObject:choice]; } else { [self.selectedChoices addObject:choice]; } CGPoint offSet = [tableView contentOffset]; [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView setContentOffset:offSet animated:NO];
But it just jumps, any suggestion?
PS I followed this topic but did not solve my question Calling reloadRowsAtIndexPaths removes tableView contentOffset
source share