Question

This is a bug that happens frequently, but not always. I have a refresh control added to my UICollectionView. When I refresh, it works perfectly. However, if I half refresh it several times or even do a full refresh, go to another tab in the app, and then return back, when I refresh, the UIRefreshControl appears over part of the UICollectionView. Additionally, instead of starting from zero refresh spinner bars, it starts with all loaded (I've noticied this in other apps such as Mail though, so that much is an OS bug, but in the OS apps, the spinner does not go over the content). Here's an image of the problem: https://www.dropbox.com/s/4qk6qjrdlapsvz0/IMG_0074.JPG Here's how I set up the RefreshController in ViewDidLoad.

refreshControl = [[UIRefreshControl alloc] init];

[refreshControl addTarget:self action:@selector(refresh2)

forControlEvents:UIControlEventValueChanged];

[self.collectionView addSubview:refreshControl];

self.collectionView.alwaysBounceVertical = YES;

Anyone know how to make the spinner go behind the CollectionViewController? Thanks

Was it helpful?

Solution

I had this issue as well and figured it out so I thought I would share. what I did was force it to the back of the UICollectionView. I had tried other things like sendSubViewToBack and setting the zIndex of the UICollectionViewCell but it didn't work. However below did work and I tested on iOS 6+:

refreshControl.layer.zPosition = -1;

For iOS 6, add this:

refreshControl.userInteractionEnabled = NO;

OTHER TIPS

Problem: You start to scroll down and partially reveal the UIRefreshControl, but you don't scroll all the way down to make it start spinning. You navigate to another view (or "minimize" app, send to background) and come back. You scroll a little and the UIRefreshControl shows on top of your collectionview fully loaded, unwelcomed and not spinning.

Solution: You need to endRefreshing on viewWillDissappear and on app being sent to background.

var refreshControl = UIRefreshControl()

override func viewDidLoad() {
    super.viewDidLoad()
    refreshControl.addTarget(self, action: #selector(ViewController.methodNameForRefreshing), forControlEvents: .ValueChanged)
    collectionView.addSubview(refreshControl)
    //or
    tableView.addSubview(refreshControl)

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.willResignActiveNotif), name: UIApplicationWillResignActiveNotification, object: nil)
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)
    refreshControl.endRefreshing()
}

func willResignActiveNotif(notification: NSNotification) {
    refreshControl.endRefreshing()
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top