我正在尝试重新加载单个tableViewCell,但是每次执行时它都会滚动到顶部...我既不添加也不删除单元格,我只想更改所选单元格的颜色。
这是我在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];
}
这就是我在didSelectRowAtIndexPath中所做的
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];
但这只是跳跃,有什么建议吗?
PS我遵循了这个线程,但没有解决我的问题调用reloadRowsAtIndexPaths删除tableView contentOffset
我知道这是一个老问题,但是我遇到了同样的问题,无法在任何地方找到答案。
之后reloadRowsAtIndexPaths:withRowAnimation:
,tableView使用中提供的估计高度确定其偏移量tableView:estimatedHeightForRowAtIndexPath:
。因此,除非您返回的值是准确的,否则实现该值将导致您的tableView的偏移量在重新加载后发生变化。我没有实现tableView:estimatedHeightForRowAtIndexPath:
,问题已解决。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句