Iglistkit: Collection Controller with Storyboard

Created on 30 Oct 2016  路  14Comments  路  Source: Instagram/IGListKit

New issue checklist

Can i use CollectionView from storyboard with multiple Cells rather SingalStoryboardCell.
i want to have Storyboard CollectionView with Multiple Cells of Autolayouts?
Or i have to create all layouts myself in CollectionViewCells?

Also Pod file have different implementation than Master branch. may be need to update pod.
e.g dequeueReusableCellFromStoryboard not found in pod IGListCollectionContext
Thanks

General information

  • IGListKit version:
  • iOS version(s):
  • CocoaPods/Carthage version:
  • Xcode version:
  • Devices/Simulators affected:
  • Reproducible in the demo project? (Yes/No):
  • Related issues:
question

Most helpful comment

@fazilakhter With reference to your issue with Cocoapods there was a discussion about this in #104

tl;dr - The team is working on a 2.0.0 release but in the meanwhile if the changes are important then master is pretty stable so you could use that.

All 14 comments

Question regarding Autolayouts and Storyboard CollectionView.

@fazilakhter You can have as many cell prototypes from storyboard as you want. Just put a switchinIGListSectionController's cellForItem(at index: Int) and dequeue different cell prototype based on index (you can also assign a different IGListSectionController for each cell prototype). There is a StoryboardViewController in examples. You can refer to it.

@fazilakhter With reference to your issue with Cocoapods there was a discussion about this in #104

tl;dr - The team is working on a 2.0.0 release but in the meanwhile if the changes are important then master is pretty stable so you could use that.

@zhubofei Thanks for the input , But what will happen in case of Autolayouts ,
Do i need to calculate size mysellf in sizeForItem ?
i want to give Cell Size according to AutoLayouts , Can you give me some pointers on this ?
what will be the best way to use Autolayouts Storyboard Cells with Correct Size e.g Image and Dynamic Text inside

@fazilakhter UICollectionViewFlowLayoutAutomaticSize only works on iOS10+. I think use sizeForItem maybe a better choice.

@zhubofei So you suggest , i calculate and give proper size myself in sizeForItem of Cells?

@fazilakhter Yes. And I think you can rely on autolayout within the cell once you set the correct size of each cell.

@zhubofei : So i want to go with Autolayout and Give Correct Size of eachCell .

Problem :
I want to get size of cell in sizeForItem function to give proper size.

when first time sizeForItem method called i don't have cells created

so i cannot get cell size properly. So i am thinking to reload but it can be expensive/hack or some other efficient solution to tackle this problem to get Cell Height properly.

@fazilakhter I find this workaround. https://github.com/honghaoz/Dynamic-Collection-View-Cell-With-Auto-Layout-Demo/blob/master/README.md
But I have to admit it is not that elegant. You can also use estimatedSize + preferredLayoutAttributesFittingAttributes though.

@fazilakhter you're running into a pretty common UICollectionView issue. Sort of a "chicken & egg" problem where you don't have the cell yet, but you have to give it the size based on data+constraints in the cell.

At Instagram we create size generators for each of our cell types to figure out how big a cell should be, given a constraining width. Though its super performant, its a very manual process and maintenance can be a pain.

I'd like to get a better grasp on UICollectionView self-sizing cells though. I created a new issue to add an example.

yes @rnystrom its like Freaking up problem ... Yes i am working on it. if i find a better solution i will fork and do a pull request with Example so you can use it later.

Btw , how did you do the generator ? like manualy calculating all heights or loading from Xib and then use that size. Also , i have notice , once all cells are there then you can do what every size you want , so reload can be an option to get size but it will cause some performance hit.

@fazilakhter take a look at #176 for an example using nibs and self-sizing cells. The same should apply to cells prototyped in a storyboard.

We mostly do height calculation in code. There's an example of that in our sample project too:

https://github.com/Instagram/IGListKit/blob/master/Examples/Examples-iOS/IGListKitExamples/Views/LabelCell.swift#L23-L33

https://github.com/Instagram/IGListKit/blob/master/Examples/Examples-iOS/IGListKitExamples/SectionControllers/ExpandableSectionController.swift#L27-L31

Sounds like we have answers to this question, right? If so let's close this issue out.

Hello @rnystrom Can you check your last examples? Links are broken.
Thanks a lot.

Updated, thanks @Ricardo1980!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kanumuri9593 picture kanumuri9593  路  3Comments

shuhrat10 picture shuhrat10  路  3Comments

runmad picture runmad  路  3Comments

PhilCai1993 picture PhilCai1993  路  3Comments

lucabartoletti picture lucabartoletti  路  3Comments