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:
rootViewController
of my UIWindow
to be my UINavigationController
.UINavigationController
by setting the viewControllers
property of the UINavigationController
.UITableViewController
subclass is instantiated with a nib.UIRefreshControl
in the viewDidLoad
method of my UITableViewController
subclass. I set the refreshControl
property of the UITableViewController
subclass in this method.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).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
.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With