Re: Can't get dynamically sized Collection View cells
Re: Can't get dynamically sized Collection View cells
- Subject: Re: Can't get dynamically sized Collection View cells
- From: Doug Hill <email@hidden>
- Date: Wed, 30 Sep 2015 16:57:58 -0700
There are few pieces of evidence that lead me to believe you that this hasn’t been done:
• A search of ADC site doesn’t show any sample code with this technique.
• A Google search turns up almost nothing, except the link I provided below.
• A search of all github and bitbucket public turns up no references to estimatedItemSize.
The funny thing is that I’ve implemented a dynamically sized table view cell using the techniques described in the WWDC presentation, and it works great. But there’s something about doing this with collection views that doesn’t quite work.
So, does Apple lie?
Thanks.
Doug Hill
> On Sep 30, 2015, at 3:54 PM, Peter Tomaselli <email@hidden> wrote:
>
> Certainly! Just to be clear (ended up revisiting some of my research on this today), I don't think it is possible to do this with just estimatedItemSize alone.
>
> So, the analogy with UITableView w/r/t "self sizing", as presented or at least strongly implied in that WWDC talk, breaks down here—you also need a "sizing cell" or some other way of performing the auto layout measurements yourself and then providing them to the delegate.
>
> I would love to be told otherwise here! But I don't believe I’ve ever seen it done.
>
> Peter
>
> On Sep 30, 2015, at 5:41 PM, Doug Hill <email@hidden <mailto:email@hidden>> wrote:
>
>> Peter,
>>
>> Thanks for the reply and the code sample. It definitely has a lot of cool stuff.
>>
>> However, I’m still interested in whether anyone else has info in on dynamically-sized Collection View cells using the ‘estimatedItemSize’ property of the flow layout. Is this a lie from a WWDC presenter? Are there a number of other steps that aren’t documented that one needs to do? Any Apple sample code that implements this?
>>
>> Apple experts please chime in!
>>
>> Doug Hill
>>
>>> On Sep 29, 2015, at 7:12 PM, Peter Tomaselli <email@hidden <mailto:email@hidden>> wrote:
>>>
>>> Hi Doug! Funny you mention this, I was trying and failing to do the same thing just tonight.
>>>
>>> Thing is, I’ve done it before and have a toy implementation on GitHub[0] to prove it! Not that that was helping me just now, of course, but perhaps a link to that repo can help you out?
>>>
>>> There are additional layers of complication in the linked project because 1. the labels inside the cells are themselves line-wrapping if necessary, so it’s quite “inside-out” as far as layout goes, and 2. the flow layout is “left-justified” instead of “fully-justified”, so be sure to ignore those aspects of the code if you do end up peeking.
>>>
>>> Anyway, to be brutally honest I can’t for the life of me remember which of the methods and/or properties in this old project are critical for getting your scenario to work, and which are related solely to mine, but perhaps it’s a decent starting point anyway.
>>>
>>> IIRC there also was a gotcha here wherein setting up your cell in IB basically meant you were SOL as far getting everything to work went (something about subviews not being embedded in the contentView properly?), but I could be wrong about that.
>>>
>>> Anyway a truly flowy layout is one of the things I most desire so if you gain any insights more, or if anyone else can chime in with better advice, I am very interested too.
>>>
>>> — Peter
>>>
>>> [0] https://github.com/Peterbing/CV-AutoLayout <https://github.com/Peterbing/CV-AutoLayout>
>>>
>>>> On Sep 29, 2015, at 6:29 PM, Doug Hill <email@hidden <mailto:email@hidden>> wrote:
>>>>
>>>> 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:
_______________________________________________
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