1

I'm having a weird issue where an UIRefreshControl is glitching when I use it in combination with an UITableView and custom UITableViewCells. If I use basic ones (set in the inspector panel in Xcode) it works just fine. See GIFs on Imgur.

Normal behaving refresh control with cell style set to basic Glitching refresh control with cell style set to custom, containing a simple UILabel

override func viewDidLoad() {
    super.viewDidLoad()

    navigationController?.navigationBar.prefersLargeTitles = true

    refreshControl = UIRefreshControl()
    refreshControl?.addTarget(self, action: #selector(self.refresh), for: .valueChanged)
    tableView.refreshControl = refreshControl

    refresh()
}

@objc func refresh() {
    tableView.reloadData()
    refreshControl?.endRefreshing()
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 8
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
    return cell!
}

Settings in inspector on UITableView and UITableViewCell are default. I'm having this issue in multiple project. The code above is in a clean project. The refresh control also jumps when prefersLargeTitles = false.

How do I get the refresh control to behave correctly with a custom TableViewCell?

3
  • Please include the image in your post and on an external site Commented Oct 15, 2017 at 22:00
  • @slashburn I don't have an high enough reputation. Commented Oct 15, 2017 at 22:02
  • Sorry, my bad :) Commented Oct 15, 2017 at 22:10

1 Answer 1

1

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.

1
  • It didn't work for me :( Do you have another suggestion? Commented Jun 13, 2019 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.