Re: Put UICollectionView within UITableViewCell
I’ll give it a shot, thank you very much > On 10 Mar 2018, at 10:27 AM, Cosmo Birchwrote: > > But you presumably know the width (i.e. the CollectionView width minus any > insets), and you can calculate the height based on that with NSString or > NSAttributedString boundingRect functions. Assuming you have a subclass for > your CollectionViewCell, you can add a method to return your cell height > based on its contents layout. > >> On Mar 9, 2018, at 8:21 AM, Gary L. Wade >> wrote: >> >> @Cosmo >> >> My collection items contain label, so I don’t know the exact sizes before >> hand. >> > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/heyhgl%40gmail.com > > This email sent to hey...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
But you presumably know the width (i.e. the CollectionView width minus any insets), and you can calculate the height based on that with NSString or NSAttributedString boundingRect functions. Assuming you have a subclass for your CollectionViewCell, you can add a method to return your cell height based on its contents layout. > On Mar 9, 2018, at 8:21 AM, Gary L. Wadewrote: > > @Cosmo > > My collection items contain label, so I don’t know the exact sizes before > hand. > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
@Cosmo My collection items contain label, so I don’t know the exact sizes before hand. @Gary In my case I actually also need to display section headers and section index titles, so using just a collection view probably won’t be easy I guess. — From the suggestions it seems it might be something very difficult to pull off. I wonder if anyone ever reverse-engineered multiline UILabels to see how table cells can have correct heights containing them. > On 10 Mar 2018, at 12:14 AM, Cosmo Birchwrote: > > Where I work we have spent a fair amount of trying unsuccessfully to get > self-sizing collection view cells to work as described by Apple documentation > with UICollectionViews that have any sort of complexity. I would suggest > trying to implement the sizeForItemAtIndexPath delegate method to see if that > solves your problem. Sorry if the name of the method is slightly off. I can’t > look it up at the moment. > >> On Mar 9, 2018, at 8:00 AM, Glen Huang wrote: >> >> Hi, >> >> I asked a question about putting UICollectionView within UITableViewCell on >> Apple Developer Forums (https://forums.developer.apple.com/thread/98176), >> but it doesn’t get many replies. I’m not sure if it’s ok to repost the >> question here. I apologize if it’s not. >> >> Here is the question: >> >> Hi, I'm trying to create a table view with cell content like this >> >> | Label | >> | CollectionItem 1 CollectionItem 2 CollectionItem 3 | >> | CollectionItem 4 | >> >> Collection view item should auto wrap at cell end, both the collection view >> and table view use automatic height. >> >> I can somewhat achieve this effect by doing: >> put the label and the collection view in a vertical stack view, make the >> stack view's each edge touch table cell's corresponding edge. >> disable collection view scrolling. >> collection view's intrinsicContentSize returns layout's >> collectionViewContentSize value. >> in table cell's prepareForReuse method, I make the collection view reload >> its data. >> >> But the problem comes when each table cell can contain different number of >> collection items: some table view cells have incorrect heights, clipping its >> collection view. My guess is that when table cells get reused, they don't >> take collection view's new intrinsicContentSize into account. >> >> I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's >> prepareForReuse method, none of them works. >> >> If I replace the collection view with a multiline label, and make each cell >> contain different length of text, the cells all have correct heights. >> >> I wonder why label are able to correctly resize cells? how can I make >> collection views do the same? >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
I would suggest rethinking the table view enclosure and just use a collection view with headers and footers by way of the supplemental views. -- Gary L. Wade http://www.garywade.com/ > On Mar 9, 2018, at 8:00 AM, Glen Huangwrote: > > Hi, > > I asked a question about putting UICollectionView within UITableViewCell on > Apple Developer Forums (https://forums.developer.apple.com/thread/98176), but > it doesn’t get many replies. I’m not sure if it’s ok to repost the question > here. I apologize if it’s not. > > Here is the question: > > Hi, I'm trying to create a table view with cell content like this > > | Label | > | CollectionItem 1 CollectionItem 2 CollectionItem 3 | > | CollectionItem 4 | > > Collection view item should auto wrap at cell end, both the collection view > and table view use automatic height. > > I can somewhat achieve this effect by doing: > put the label and the collection view in a vertical stack view, make the > stack view's each edge touch table cell's corresponding edge. > disable collection view scrolling. > collection view's intrinsicContentSize returns layout's > collectionViewContentSize value. > in table cell's prepareForReuse method, I make the collection view reload its > data. > > But the problem comes when each table cell can contain different number of > collection items: some table view cells have incorrect heights, clipping its > collection view. My guess is that when table cells get reused, they don't > take collection view's new intrinsicContentSize into account. > > I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's > prepareForReuse method, none of them works. > > If I replace the collection view with a multiline label, and make each cell > contain different length of text, the cells all have correct heights. > > I wonder why label are able to correctly resize cells? how can I make > collection views do the same? > > Thanks very much. > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Put UICollectionView within UITableViewCell
Where I work we have spent a fair amount of trying unsuccessfully to get self-sizing collection view cells to work as described by Apple documentation with UICollectionViews that have any sort of complexity. I would suggest trying to implement the sizeForItemAtIndexPath delegate method to see if that solves your problem. Sorry if the name of the method is slightly off. I can’t look it up at the moment. > On Mar 9, 2018, at 8:00 AM, Glen Huangwrote: > > Hi, > > I asked a question about putting UICollectionView within UITableViewCell on > Apple Developer Forums (https://forums.developer.apple.com/thread/98176), but > it doesn’t get many replies. I’m not sure if it’s ok to repost the question > here. I apologize if it’s not. > > Here is the question: > > Hi, I'm trying to create a table view with cell content like this > > | Label | > | CollectionItem 1 CollectionItem 2 CollectionItem 3 | > | CollectionItem 4 | > > Collection view item should auto wrap at cell end, both the collection view > and table view use automatic height. > > I can somewhat achieve this effect by doing: > put the label and the collection view in a vertical stack view, make the > stack view's each edge touch table cell's corresponding edge. > disable collection view scrolling. > collection view's intrinsicContentSize returns layout's > collectionViewContentSize value. > in table cell's prepareForReuse method, I make the collection view reload its > data. > > But the problem comes when each table cell can contain different number of > collection items: some table view cells have incorrect heights, clipping its > collection view. My guess is that when table cells get reused, they don't > take collection view's new intrinsicContentSize into account. > > I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's > prepareForReuse method, none of them works. > > If I replace the collection view with a multiline label, and make each cell > contain different length of text, the cells all have correct heights. > > I wonder why label are able to correctly resize cells? how can I make > collection views do the same? > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Put UICollectionView within UITableViewCell
Hi, I asked a question about putting UICollectionView within UITableViewCell on Apple Developer Forums (https://forums.developer.apple.com/thread/98176), but it doesn’t get many replies. I’m not sure if it’s ok to repost the question here. I apologize if it’s not. Here is the question: Hi, I'm trying to create a table view with cell content like this | Label | | CollectionItem 1 CollectionItem 2 CollectionItem 3 | | CollectionItem 4 | Collection view item should auto wrap at cell end, both the collection view and table view use automatic height. I can somewhat achieve this effect by doing: put the label and the collection view in a vertical stack view, make the stack view's each edge touch table cell's corresponding edge. disable collection view scrolling. collection view's intrinsicContentSize returns layout's collectionViewContentSize value. in table cell's prepareForReuse method, I make the collection view reload its data. But the problem comes when each table cell can contain different number of collection items: some table view cells have incorrect heights, clipping its collection view. My guess is that when table cells get reused, they don't take collection view's new intrinsicContentSize into account. I tried calling sizeToFit/layoutIfNeeded/updateConstraints in cell's prepareForReuse method, none of them works. If I replace the collection view with a multiline label, and make each cell contain different length of text, the cells all have correct heights. I wonder why label are able to correctly resize cells? how can I make collection views do the same? Thanks very much. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com