[英]Tableview with no animation still jitters when I reload section
In a tableview's section. 在表格视图的部分中。 I have some selectable rows.
我有一些可选的行。 Inside the section's header I have a
Deselect All
button. 在该部分的标题内,我有一个
Deselect All
按钮。
The deselect all
button needs to get enabled if a row is selected and disabled if no row is selected. 如果
deselect all
某行,则需要启用deselect all
按钮;如果没有选择任何行,则需要禁用该按钮。 The button is enabled/disabled by reading a boolean value. 通过读取布尔值可以启用/禁用该按钮。 I have a
didSet
on that boolean: 我在该布尔值上有一个
didSet
:
var shouldEnableDeselectButton = false
{
didSet{
if oldValue != shouldEnableDeselectButton{
DispatchQueue.main.async {
self.notesTable.reloadSections([self.indexofFilter], with: .none)
}
}
}
}
didSet
then it only gets updated by being dequeued/scrolling up or down and getting off the screen. didSet
绝对不执行任何操作,则只能通过出队列/向上滚动或向下滚动并离开屏幕来进行更新。 See below: self.notesTable.reloadSections([someSection], with: .none)
then it longer requires the section header to get dequeued. self.notesTable.reloadSections([someSection], with: .none)
则它更长的时间要求节标题出队。 Yet if I select one of the last rows, then it jitters badly: See below: I looked online and found solutions mentioned Reload tableview section without scroll or animation but they both still jitter 我在网上看了看,发现解决方案中提到的Reload tableview部分没有滚动或动画,但它们仍然抖动
2 things were needed: 需要做两件事:
Get a reference/pointer to the headerView. 获取对headerView的引用/指针。 Eg this answer.
例如这个答案。
Have your button as a property . 将按钮作为属性 。 I was originally having it just as a subview.
我最初只是将其作为子视图使用。 That wasn't enough!
那还不够! To do such I made my sectionHeader a
UITableViewHeaderFooterView
subclass and then added the button as a property. 为此,我将sectionHeader设置为
UITableViewHeaderFooterView
子类,然后将按钮添加为属性。
Then I was simply able to change the isEnabled
property of the button. 然后,我
isEnabled
更改按钮的isEnabled
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.