Search code examples
swiftuicollectionviewrestkitnsfetchedresultscontroller

UICollectionViewController halts scrolling when inserting new cells


I have a UICollectionView that is endlessly scrolling. As the user scrolls, the controller makes API requests for new pages, usually loading the next page before the user gets to the bottom of her feed. However, when the UIViewController updates with new data via a fetchedResultsController, the scrolling stops, even if the items are off the screen. This results a glitchy scroll experience for the user. How can I stop interrupting the scrolling?

This is how I'm implementing the insertion:

https://stackoverflow.com/a/28878296/310385

EDIT

This does not appear to be an issue with performing a halting operation on the main thread. It seems that the scrolling is being actively stopped. I ran the following code:

func updateCollection(){
    collectionView?.performBatchUpdates({ () -> Void in 
        //perform insertions
        println("Insertions started")
    }), 
    completion: {(completed) -> Void in 
        println("Completed")
    }
}

override func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    println("End Decelerating")
}

And it prints this consistently:

Insertions started
End Decelerating
Completed

Solution

  • It turns out I had a UIRefreshControl object that was calling endRefreshing() when I downloaded new data. This apparently halts scrolling.