I've noticed a little bug (but really annoying) when I use UIRefreshControl
in my View Controller. When the application returns from the background the UIRefreshControl
is already loaded and it looks like this:
As you can see I use a custom navigation controller which hides like in the Facebook app (AMScrollingNavBar
). When I reload data in UITableView
everything comes back to normal and this bug shows only after returning from the background.
This is the code which I use to initialize UIRefreshControl
in viewDidLoad
:
// Initializing generic refresh control
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(collectData) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:self.refreshControl];
This is a known bug in iOS7. You can see it reproduce in Apple's mail app. I can confirm it has not been fixed as of
iOS7.1 beta 5iOS8.0 beta 3iOS 10.0.1.First, open a bug report at https://bugreport.apple.com/ My radar number is
rdar://14586451
, which is a duplicate ofrdar://14493713
(still open).A proposed fix is to register for
UIApplicationWillEnterForegroundNotification
notifications in your view controller and call[self.refreshControl.superview sendSubviewToBack:self.refreshControl];
to somewhat remedy the issue by having the refresh control appear behind your table content.I see in the second screenshot that the refresh control shows under your cell. This is likely because you have set a clear color as your cell's background. Set it to white.
This bug seems to occur when making a modal presentation over the table view controller as well as when the app returns from the background.
The simplest fix is to call
endRefreshing()
inviewWillAppear(_:)
and upon receiving the notificationUIApplicationWillEnterForeground
. You need to do both becauseviewWillAppear(_:)
is not called when the app returns from the background.The effect of calling
endRefreshing()
on an instance of UIRefreshControl appears to be to return the control to the correct location in the view hierarchy and ensure that it continues to animate correctly on subsequent refreshes.Remember to check that your refresh control is, in fact, not refreshing.
In Swift:
Tested in Xcode 7.0 targeting iOS 8.0 with a UITableViewController configured in the storyboard.
I found one workaround for a variation of this bug. It might potentially help with yours, too. In my app, switching to another tab and going back to the tab with the refresh control broke it - the control didn't animate any more while dragging.
Instead of setting up UIRefreshControl in viewDidLoad, I set it up in viewDidAppear, and then always remove it in viewDidDisappear. This way it's always initialised fresh and doesn't get confused.
As in the previous answer to this question, i've requested UIApplicationDidBecomeActiveNotification so that the refresh control can be fixed also when the user jumps back in the app.
Slightly suboptimal, but works.