30

I have a UITableViewController on which I set a backgroundView. This controller has a UIRefreshControl installed. The problem is that when I set a background view, the refresh control is invisible. If I remove the background view, I can see the refresh control.

Am I doing something wrong?

leftspin
  • 2,468
  • 1
  • 25
  • 40
  • 1
    If you appreciate any of the answers below, please mark one of them as the right answer. This will increase your reputation, and the answer composer's. – gardenofwine Oct 15 '13 at 12:00

4 Answers4

88

The reason for this behavior is that in iOS 7, the UITableView's backgroundView is drawn above the UIRefreshControl. Not sure if this is by design or an issue, but here is a workaround that fixed it for me :

   self.tableView.backgroundView.layer.zPosition -= 1;

This code goes where you set up your UITableViewController refreshControl property.

Champoul
  • 1,004
  • 7
  • 15
  • 27
    This works. Here's another perhaps more semantically clear way: `self.refreshControl.layer.zPosition = self.tableView.backgroundView.layer.zPosition + 1;` – Donald Sep 27 '13 at 17:10
  • Give this guy a Beer! Thanks for this! :) – TeaCupApp Apr 13 '14 at 11:59
  • 1
    This is so ugly but it saved me from my misery. Thanks Champoul! – Michal Sep 03 '14 at 08:53
  • This is not a good solution if you have a search bar because it causes the refresh control to appear overtop the search bar. – Jordan H Dec 04 '14 at 17:39
0

You could try sending the background to the back or the refresh control to the front. The refresh control is more than likely just sitting at index 0.

Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
0

It seems that UITableViewController pushes its UIRefreshControl to back to the 0 index during reload (behind its "backgroundView"), regardless at what index you put it in the first place. This is what worked for me (iOS 9): Disable refreshing in IB. Create UIRefreshControl in code and add it to tableView after setting up backgroundView:

    let someView = UIView()

    self.tableView.backgroundView = someView

    let refreshControl = UIRefreshControl()

    refreshControl.addTarget(self, action: #selector(MyTableViewController.refresh(_:)), forControlEvents: .ValueChanged)

    self.tableView.insertSubview(refreshControl, atIndex: 1)
Jovan Stankovic
  • 4,661
  • 4
  • 27
  • 16
-2

This issue is easily fixed by not using the self.refreshControl property on the UITableViewController, instead create you own property for it and it will work just fine.