Occasionally my table view won\'t be connected to a service to refresh, and in that case, I don\'t want the UIRefreshControl to be present.
After I add it in viewDid
There’s a very simple solution you can try: [self.refreshControl removeFromSuperview];
I solved this problem by calling "yourRefreshControl".endEditing()
inside the refresh function.
Try this:
[self.refreshControl removeFromSuperview];
self.refreshControl = nil;
An old question, but I was looking for an answer and nothing worked exactly like I wanted.
This is what worked for me:
Swift 4
func createRefreshControl() {
refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(self.myTableRefreshFunction), for: UIControlEvents.valueChanged)
refreshControl?.tintColor = UIColor.white
refreshControl?.endRefreshing()
}
func removeRefreshControl() {
refreshControl?.removeTarget(self, action: #selector(self.myTableRefreshFunction), for: UIControlEvents.valueChanged)
refreshControl = nil
}
I call createRefreshControl() when I want the control created, and removeRefreshControl when I want it removed.
I had to remove the same target I initially added to the refresh control, otherwise it would refresh one time before it was actually removed.
To hide refresh control and avoid warning Just use
Objective C
[self.refreshControl removeFromSuperview];
Swift
self.refreshControl.removeFromSuperview()
[refreshControl setTintColor:[UIColor clearColor]];
also you can do something like this:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y < 0)
scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}