【发布时间】:2015-01-22 01:12:12
【问题描述】:
我正在尝试重新加载单个 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];
但它只是跳跃,有什么建议吗?
附言 我关注了这个帖子,但它没有解决我的问题Calling reloadRowsAtIndexPaths removes tableView contentOffset
【问题讨论】:
-
尝试 UITableViewRowAnimationNone 并删除 [tableView setContentOffset:offSet animated:NO];
-
嗨 Sathya... 它仍然滚动到顶部,现在它没有那么好的褪色效果嘿嘿嘿:'(
标签: ios uitableview reload