内容简介:在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时保持偏移量》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Linux二进制分析
[美]瑞安 奥尼尔 / 棣琦 / 人民邮电出版社 / 2017-12-1 / CNY 59.00
二进制分析属于信息安全业界逆向工程中的一种技术,通过利用可执行的机器代码(二进制)来分析应用程序的控制结构和运行方式,有助于信息安全从业人员更好地分析各种漏洞、病毒以及恶意软件,从而找到相应的解决方案。 本书是一本剖析Linux ELF工作机制的图书,共分为9章,其内容涵盖了Linux环境和相关工具、ELF二进制格式、Linux进程追踪、ELF病毒技术、Linux二进制保护、Linux中的E......一起来看看 《Linux二进制分析》 这本书的介绍吧!