UIRefreshcontrol jitters when pulled down and held

后端 未结 7 562
野趣味
野趣味 2021-01-01 23:21

I have created a UIRefreshcontrol in my tableviewcontroller as follows in the viewdidload method :

    refresh = [UIRefreshControl.alloc init];
    refresh.a         


        
相关标签:
7条回答
  • 2021-01-02 00:17

    My solution is similar to the accepted solution. The idea is to update your table view only after the view is at the right place. Therefore, we can add a variable to track if we need to update the view when the scroll view is completely bounced back (don't update it while decelerating).

    Also, always update your table view before ending the refreshControl.

    // The action function of refreshControl
    @objc private func refresh() {
        DispatchQueue.global(qos: .utility).async {
            // Update data
            // ......
    
            // Update the table view
            DispatchQueue.main.async {
                if self.tableView.isDragging == false {
                    self.tableView.reloadData()
                    self.myRefreshControl.endRefreshing()
                } else {
                    self.needEndRefreshing = true
                }
            }
        }
    }
    
    override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if self.needEndRefreshing {
            self.tableView.reloadData()
            self.myRefreshControl.endRefreshing()
            self.needEndRefreshing = false
        }
    }
    
    0 讨论(0)
提交回复
热议问题