在reloadRowsAtIndexPaths时保持偏移量

mtet88

我正在尝试重新加载单个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

ey

我知道这是一个老问题,但是我遇到了同样的问题,无法在任何地方找到答案。

之后reloadRowsAtIndexPaths:withRowAnimation:,tableView使用中提供的估计高度确定其偏移量tableView:estimatedHeightForRowAtIndexPath:因此,除非您返回的值是准确的,否则实现该值将导致您的tableView的偏移量在重新加载后发生变化。我没有实现tableView:estimatedHeightForRowAtIndexPath:,问题已解决。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

当 lambda 中的事件失败时,kinesis 如何保持偏移量并再次推送记录

来自分类Dev

使用Glyphter.com将SVG转换为字体时的偏移量-偏移量

来自分类Dev

为什么在Silverstripe中调用增量偏移量方法时,偏移量不会增加?

来自分类Dev

偏移量存储为Kafka时如何检查消费者偏移量?

来自分类Dev

使用Glyphter.com将SVG转换为字体时的偏移量-偏移量

来自分类Dev

pygame:翻转时怪异的精灵偏移量?

来自分类Dev

当偏移量可变时,如何获取“ next”事件?

来自分类Dev

出现键盘时,它会重置内部视图的偏移量

来自分类Dev

宽度<1680时,BootStrap移除偏移量

来自分类Dev

发生异常时如何获取IL指令偏移量?

来自分类Dev

指定区域时,Luxon DateTime fromISO错误的偏移量

来自分类Dev

使用动画移动时获取元素的偏移量

来自分类Dev

旋转到触摸位置时的ccsprite旋转偏移量

来自分类Dev

Python:RuntimeError:导入模块时插槽偏移量无效

来自分类Dev

使用“爆炸”时未定义的偏移量

来自分类Dev

出现键盘时,它会重置内部视图的偏移量

来自分类Dev

Cron * / 6小时但有偏移量吗?

来自分类Dev

错误使用爆炸时未定义的偏移量

来自分类Dev

在Perl中提取单词偏移量时出错

来自分类Dev

strtotime 时的奇怪行为 - 登录偏移量

来自分类Dev

当API不支持偏移量时,如何从偏移量获取结果(HERE Maps API)

来自分类Dev

时区偏移量被忽略

来自分类Dev

偏移量类型错误

来自分类Dev

jQuery Waypoint偏移量

来自分类Dev

DatetimeIndex的偏移量为

来自分类Dev

日历偏移量问题

来自分类Dev

时区偏移量被忽略

来自分类Dev

ls |头(偏移量?)

来自分类Dev

结构的 glBufferSubData 偏移量

Related 相关文章

热门标签

归档