Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.87k stars 1.54k forks source link

How to return datasource count in section controller numberOfItems #341

Closed otymartin closed 7 years ago

otymartin commented 7 years ago

@rnystrom

In my sectionController numberOfItems, I would like to return my dataArray.count as opposed to just return 1 per sectionController. My dataArray.count varies as its populated by network queries.

The problem is my dataArray is in my viewController which is my datasource.

I can try to instantiate my viewController in my sectionArray and access the dataArray.count but problem I found is numberOfItems and I think the whole sectionController loads before my viewController's viewDidLoad method resulting in nil for my dataArray.count.

How can I fix this?

New issue checklist

General information

rnystrom commented 7 years ago

@otymartin instead of using the mutable dataArray.count in the section controller, I would use an immutable object that represents the data in your section. Whenever a network request finishes, you can call performUpdates(...) and recreate your immutable models.

Take a look at my weather app data source as an example. Anytime something changes I recreate the models which power my different section controllers.

otymartin commented 7 years ago

Thanks @rnystrom Looks like I have to dive into a new topic immutable models. Thanks for providing your code, its helping alot.

jessesquires commented 7 years ago

🎉