内容简介:在reloadRowsAtIndexPaths:withRowAnimation:之后,tableView使用tableView:estimatedHeightForRowAtIndexPath:中给出的估计高度确定其偏移量.因此,除非您返回的值是准确的,否则实现它将导致tableView的偏移量在重新加载后发生变化.我没有实现tableView:estimatedHeightForRowAtIndexPath:问题得到解决.翻译自:https://stackoverflow.com/questions/2
我正在尝试重新加载一个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];
但它只是跳,任何建议?
P.S
我跟着这个帖子,但它没有解决我的问题 Calling reloadRowsAtIndexPaths removes tableView contentOffset
在reloadRowsAtIndexPaths:withRowAnimation:之后,tableView使用tableView:estimatedHeightForRowAtIndexPath:中给出的估计高度确定其偏移量.因此,除非您返回的值是准确的,否则实现它将导致tableView的偏移量在重新加载后发生变化.我没有实现tableView:estimatedHeightForRowAtIndexPath:问题得到解决.
翻译自:https://stackoverflow.com/questions/27102887/maintain-offset-when-reloadrowsatindexpaths
以上所述就是小编给大家介绍的《ios – reloadRowsAtIndexPaths时保持偏移量》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 记一次Access偏移注入
- Kafka 消息偏移量的维护
- Spark Streaming 之 Kafka 偏移量管理
- php-rdkafka手动提交偏移量
- 人品爆发:偏移注入与移位溢注的联合使用
- bug诞生记——隐蔽的指针偏移计算导致的数据错乱
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Spring技术内幕
计文柯 / 机械工业出版社 / 2010-1-1 / 55.00元
内容简介: 本书是Spring领域的问鼎之作,由业界拥有10余年开发经验的资深Java专家亲自执笔!Java开发者社区和Spring开发者社区一致强烈推荐。 国内第一本基于Spring3.0的著作,从源代码的角度对Spring的内核和各个主要功能模块的架构、设计和实现原理进行了深入剖析。你不仅能从木书中参透Spring框架的优秀架构和设计思想,而且还能从Spring优雅的实现源码中一窥......一起来看看 《Spring技术内幕》 这本书的介绍吧!