UIRefreshControl hidden / obscured by my UINavigationController's UINavigationBar

Tim Arnold picture Tim Arnold · Feb 6, 2013 · Viewed 8.3k times · Source

I'm attempting to use a UIRefreshControl inside my UITableViewController which itself is inside a UINavigationController, which has its hidesNavigationBar property set to NO (so the navigation bar is visible).

The UIRefreshControl works, but is obscured by the UINavigationBar. I'm surprised I can't find anyone else who has run into this problem.

Possible relevant points:

  • I set the rootViewController of my UIWindow to be my UINavigationController.
  • I set the initial view controller of the UINavigationController by setting the viewControllers property of the UINavigationController.
  • My UITableViewController subclass is instantiated with a nib.
  • I instantiate my UIRefreshControl in the viewDidLoad method of my UITableViewController subclass. I set the refreshControl property of the UITableViewController subclass in this method.
  • The UIRefreshControl works perfectly fine, and I can see a portion of it, but it is obscured by my UINavigationBar. It looks completely normal if I set hidesNavigationBar to YES (but I don't want to hide it).

Edit:

The code used to create and position my UIRefreshControl is:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self 
                   action:@selector(toggleRefresh:) 
         forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;

This code snippet is in the viewDidLoad method of my UITableViewController subclass, which is a child view controller of a UINavigationViewController.

Answer

Alex Pretzlav picture Alex Pretzlav · Sep 18, 2013

For those targeting iOS 7, there seems to be a new issue present where the UIRefreshControl is drawn behind the UITableView's backgroundView. I experienced this both when initializing the UIRefreshControl programatically and from a storyboard. A simple workaround is to update the zPosition of the UIRefreshControl in viewDidLoad of your UITableViewController:

self.refreshControl.layer.zPosition = self.tableView.backgroundView.layer.zPosition + 1;