2

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
Community
  • 1
  • 1
rob
  • 4,069
  • 3
  • 34
  • 41
  • Don't get / parse data on the main thread. Do it on a background thread, then update the main thread when you have the results. – Aaron Brager May 18 '15 at 18:10
  • I'm using restkit, so the requests and their parsing should be done on background threads. – rob May 18 '15 at 18:44
  • Something expensive is being done on the main thread. If you're not sure what it is, you can use the Time Profiler instrument to see what calls are taking how much time. – Aaron Brager May 18 '15 at 18:45
  • Looking into it I think you may be right. There's an issue [here](https://github.com/RestKit/RestKit/issues/1318) with restkit performing core data operations on the main thread. Following the poster's recommendation resulted in empty collection views, though. I'll dig a little more... – rob May 18 '15 at 19:05
  • It doesn't appear to be a halting operation on the main thread. (See my edit.) – rob Jun 17 '15 at 21:42

1 Answers1

4

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

rob
  • 4,069
  • 3
  • 34
  • 41