Bug with scrollsToTop and UIRefreshControl

1.1k Views Asked by At

I have a bug in my iOS App. I'm using a UITableView, in which I implemented a "pull to refresh" controller like this :

self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.backgroundColor = [UIColor clearColor];
self.refreshControl.tintColor = [UIColor blackColor];
[self.refreshControl addTarget:self
                            action:@selector(loadTheXML)
                  forControlEvents:UIControlEventValueChanged];

But, I have a little bug. If I scroll down the table, and if I tap the status bar to scroll to the top of the table, the refresh controller is partially displayed. Here a gif of what is happening : gif link.

If I use this refresh controller one time, the bug is not happening anymore, when I tap the status bar, it scrolls to the top of table.

Any idea on how to fix this bug ?

3

There are 3 best solutions below

0
On BEST ANSWER

I am experiencing the same bug, and it only happens when you have an attributed title. It also happens, if I first time tap a search bar, the result is the same. Here is a workaround that worked for me:

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
     if(self.refreshControl!=nil)
     {
          [self.refreshControl beginRefreshing];
          [self.refreshControl endRefreshing];
     }
     return scrollView.scrollsToTop;
}
0
On

I was also having the same issue. In my code I was reloading the UITableView and then setting the attributed title for the refresh control.

The resolution is to first set the title of the refresh control and then reload the UITableView.

0
On

A slightly improved version of AlexeyIS’ workaround will call that code only once:

- (void)awakeFromNib {
    super.awakeFromNib();

    if (self.refreshControl != nil) {
        [self.refreshControl beginRefreshing];
        [self.refreshControl endRefreshing];
    }
}