I have a UITableViewController as the root view controller in a UINavigationController, which is in turn one of the view controllers in a UITabBarController. All hooked up in Storyboard.
I've configured the UIRefreshControl for my table in Storyboard as well, and normally it looks like it should when pulling:
However, if I switch between my other tabs once or twice, it looks like this:
It's not spinning or anything, just stuck "full", and it stays that way until I pull fully and trigger a refresh.
Any ideas or suggestions appreciate.
While refresh control is spinning, if you present some other controller and come back before "end refreshing"; refresh animation will be stuck.
None of the answers above worked for me, and I didn't want to set bool and follow it through all lifecycle of a view controller.
My solution is adding below code to end of viewWillAppear.
in Objc;
in Swift;
Logic is; whenever it catches refresh control is in the state of animating, it will stop it without knowing it is stuck or not and re-run the animation.
Hope it helps.
After running into the same problem several times I decided to make a library for it SwiftPullToRefresh.
As said before,
refreshControl
needs to be stoped onviewDidDisappear(_:)
and started onviewWillAppear(_:)
.When programatically starting
refreshControl
animation,tableView.contentOffset
needs to be set to appropriate value.The following solution may help you.
Simply calling
endRefreshing
inviewWillDisappear:
fixed all the issues for me.Doing the same thing in
viewWillAppear:
caused the refresh control to rotate strangely when pulling the table.