UIRefreshControl glitching in combination with custom TableViewCell

二次信任 提交于 2019-12-07 15:15:28

The way I avoid the above glitch nowadays is by delaying the tableView.reloadData() call for a small amount of time:

self.tableView.refreshControl?.endRefreshing()
self.tableView.perform(#selector(self.tableView.reloadData), with: nil, afterDelay: 0.05)

Not really a fix but more of a hack in my opinion.

This is how I go about adding a refresh control in my UITableView with custom cells.

lazy var refreshControl: UIRefreshControl = {

    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: UIControlEvents.valueChanged)
    return refreshControl

}()

func refresh(_ refreshControl: UIRefreshControl) {

    self.tableView.reloadData()
}

override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.addSubview(refreshControl)
}

Possibly add endRefreshing when you're done with a task, and not in the action of the refreshControl itself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!