简体   繁体   English

重新加载部分时没有动画的Tableview仍然抖动

[英]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)
                }
            }
        }
    }
  • If I do absolutely nothing in the didSet then it only gets updated by being dequeued/scrolling up or down and getting off the screen. 如果我在didSet绝对不执行任何操作,则只能通过出队列/向上滚动或向下滚动并离开屏幕来进行更新。 See below: 见下文:

在此处输入图片说明

  • If I do 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: 需要做两件事:

  1. Get a reference/pointer to the headerView. 获取对headerView的引用/指针。 Eg this answer. 例如这个答案。

  2. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM