Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIRefreshControl hidden / obscured by my UINavigationController's UINavigationBar

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.

like image 424
Tim Arnold Avatar asked Feb 06 '13 21:02

Tim Arnold


2 Answers

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;
like image 86
Alex Pretzlav Avatar answered Sep 28 '22 02:09

Alex Pretzlav


I've find a real solution, here it is:

I've a UIViewController inside a UINavigationController with a translucent NavigationBar. Inside the UIViewController there is the UITableView.

I want to add a UIRefreshControl but when I do it, it's hidden by the NavigationBar, like you explain.

Here is my code to make it work:

// Add a UITableViewController
self.tblViewController = [[UITableViewController alloc] init];

// Set the UITableView to it
self.tblViewController.tableView = self.tblView;

// Initialize the UIRefreshControl and set it's method
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];

// Set the RefreshControl to the UITableViewController
self.tblViewController.refreshControl = self.refreshControl;

// Here is the thing ! Just change the contentInset to push down the UITableView content to 64 pixels (StatusBar + NavigationBar)
self.tblView.contentInset = UIEdgeInsetsMake(64.f, 0.f, 0.f, 0.f);

With this code, your UITableViewController will show the RefreshControl perfectly and keep the translucent NavigationBar effect when you scroll down the cells.

like image 30
Jonathan Avatar answered Sep 28 '22 03:09

Jonathan