App Info Auto Sizing Cells
AppStore JSON APIs
With our Detail Cell now being rendered with the necessary subviews, we'll move on by fill out each view with the app information that we fetch in the last episode. This will require that we reload our collection view after the data fetch and implement more logic in cellForItemAt. At the end of this lesson, we'll go over how to calculate auto sizing for cells that containing both really long and short release notes updates.

Comments (6)
johnrm9
4 years ago
Hi Brian, Awesome course! CGFloat.greatestFiniteMagnitude works too for initial height in auto sizing AppDetailCell: class AppDetailController: ... ... func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let size: CGSize = .init(width: view.frame.width, height: .greatestFiniteMagnitude) let dummyCell = AppDetailCell(frame: .init(origin: .zero, size: size)) dummyCell.app = self.app dummyCell.layoutIfNeeded() let estimatedSize = dummyCell.systemLayoutSizeFitting(size) return .init(width: view.frame.width, height: estimatedSize.height) }
ayon
4 years ago
PreachOnBerto
4 years ago
Nice!!!
stevezhou
4 years ago
Nope, it doesn't work in the latest OS
Brian Voong
4 years ago
Steven Hayes
4 years ago
Be careful with using .greatestFiniteMagnitued, when you run your project and go to the app details you will see the following in your console. This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on BOOL _NSLayoutConstraintNumberExceedsLimit(void) to debug. This will be logged only once. This may break in the future.
richardbranson
4 years ago
Hey Brian! First of all :) Thank you for the course I have a question regarding this line of code. let estimatedSize = dummyCell.systemLayoutSizeFitting(.init(width: view.frame.width, height: 1000)) My question is :-> Why are we using a arbitrary value of 1000 to specify the height of estimatedSize?
Brian Voong
4 years ago
sereisoglu
4 years ago
If we type 0 instead of height, the result does not change. Why?
Brian Voong
4 years ago
skuenstler
4 years ago
Hi Brian, thank you very much for the course - I learn a lot! One question related to episode 21 of this course: How would you go about the Auto-sizing if the Cell had a height-animation ?? Can you make the sizeForItemAt react to a height-animation and make the collectionView's-size go with it ? Below here are two stack overflow questions that I created around this problem (including a video) - maybe you have a moment to look into it: Thank you for any help on this ! https://stackoverflow.com/questions/55705717/how-to-resize-collectionview-or-tableview-cell-from-custom-cell-class https://stackoverflow.com/questions/55691684/expandable-uicollectionviewcell-works-only-after-scrolling
Brian Voong
4 years ago
skuenstler
4 years ago
Thank you Brian, that makes sense - tough not having any experience with custom implementation of UICollectionViewFlowLayout, I definitely give it a try. Again, thanks for replying this fast. And again, I really like the way your courses are structured. Big thumbs up !
Eugeneberezin
3 years ago
Thank you! It was very helpful. Is there a similar method for tableView cell?
Skander
3 years ago
I don't know how the code will evolve to add the screenshot images afterwards, but currently I managed to get the cell to autosize by the giving a height of view.frame.height to the AppDetailCell and add a UIView() at the bottom of the vertical stack used to layout the cell views.
Israel Delmayor
3 years ago
Hi i know this all programatically and it works well. I noticed when I tried to apply this on a nib cell. it getting crash. Have anyone experiencing on it?
HELP & SUPPORT