Can't get dynamically sized Collection View cells
Can't get dynamically sized Collection View cells
- Subject: Can't get dynamically sized Collection View cells
- From: Doug Hill <email@hidden>
- Date: Tue, 29 Sep 2015 15:29:50 -0700
I’m trying to implement a collection with dynamically sized cells. The WWDC session from 2014 “What’s New in Table and Collection Views” talks about how to do this by:
• Use autolayout constraints to set the height of the cell based on the content size of the subviews.
• Set the estimatedItemSize property of the flow layout object to get the scrollbars to be in close the correct location.
This doesn’t seem to work as I see the following log message:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
Please check the values return by the delegate.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7c218e20>, and it is attached to <UICollectionView: 0x7a411c00; frame = (0 0; 205 615); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7c7674f0>; layer = <CALayer: 0x79e25060>; contentOffset: {0, 0}; contentSize: {205, 66}> collection view layout: <UICollectionViewFlowLayout: 0x7c218e20>.
2015-09-29 14:48:29.255 Chartcube[65578:3340001] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
also
the behavior of the UICollectionViewFlowLayout is not defined because:
the item width must be less than the width of the UICollectionView minus the section insets left and right values.
Please check the values return by the delegate.
FWIW I don’t set any other properties of the flow layout.
Doing a Google search leads me to the following page:
http://corsarus.com/2015/collection-view-with-self-sizing-cells/
which discusses this error message and how to add another constraint at runtime to fix it. It sets a fixed width constraint of the cell content view. This “solution” appears to be a bit of a hack since they did some trial and error to figure out how to set it so that it would make things work. This leads me to believe there’s something else going on. Also, it would be great to know why I get the error in the first place. Maybe there’s some other setting in the flow layout that needs to be made?
Can someone comment on how to implement dynamically-sized collection view cells correctly? Unfortunately, the WWDC session doesn’t go into detail on how they got their collection view to autoresize the cells and there’s isn’t any sample code for the project described in the video. It would be great to know the “approved” way to implement this behavior.
Thanks!
Doug Hill
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden