Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Dynamically loading cells for UICollectionView

Hey guys. I'm trying to figure out how to dynamically load content of a UICollectionView when the user scrolls down to the bottom of the view. I've seen several threads about this online, but nothing that really hits what I'm looking for with updated code for the latest OS's. So basically what I'm doing is sending a request to Instagram API to populate my collection view, much like the Photobombers app, but I want to load more cells, thus expanding the height of the collection view, when the user hits the bottom of the currently loaded batch of images. A good example is the "explore" section of Instagram or Phonegram.

3 Answers

So I made a huge mistake. Turns out the data array we constructed in the Photobombers app was immutable, so adding objects to it are obviously not allowed. Also the array retrieved from the responseDictionary is immutable. So what I did was change the data array from an NSArray to an NSMutableArray and instantiate it using the values retrieved from the responseDict with the "arrayWithArray:" class method. Problem solved. Now the app infinitely scrolls with new images being loaded in new cells!

Would you like the user to be notified when they reach to the bottom, or just have endless scrolling ?

I'd like the user to know when they've reached the bottom with displaying something like an ActivityView on the main thread before more content is loaded (as opposed to preloading more cells).

So I was able to find some categories on Github that does the complex work for me, but I still have to think about how I can load more items into these new cells without having to reload the entire collection view.

(https://github.com/samvermette/SVPullToRefresh)