(apologies if this is a duplicate. I asked this question yesterday, but can't find it in search results now)
This question describes code that is working nicely in iOS 9.3, but not nicely in iOS 10.0.0
I have a UICollectionView that lives in a UITableViewCell.
At anytime, I need the collectionView's frame to match its contentSize. and the parent cell's height to match the contentSize.height.
When the contents of the collectionView change or the device rotates, I need to change the height of the cell and the frame of the collectionView.
I am doing by setting the cell's tableHeight to UITableViewAutomaticDimension and overriding the tableViewCell's systemLayoutSizeFittingSize:
- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority
{
if ([self hasImages])
{
self.images.frame = CGRectMake(0, 0, targetSize.width, MAXFLOAT);
[self.images layoutIfNeeded];
[self.title layoutIfNeeded];
CGFloat collectionHeight = [self.images.collectionViewLayout collectionViewContentSize].height;
CGSize result = targetSize;
result.height = collectionHeight + kSpaceBelow + self.title.frame.origin.y + self.title.frame.size.height + kSpaceAbove;
return result;
}
targetSize.height = 95;
return targetSize;
}
as I said, this works marvellously in iOS 9.3, however in not so marvelously on iOS 10.
on iOS 10, control never returns from [self.images layoutIfNeeded]; at line6
when I pause execution I see stack trace below. (both on simulator and an iPhone7)
1. Am I doing something unwise in my code?
2. if not, is this a known thing?
3. if not, what should I do?
thanks!
Mike
#0 0x000000018f6eb708 in -[UICollectionViewData layoutAttributesForElementsInRect:] ()
#1 0x000000018f6e8e7c in -[UICollectionView _updateVisibleCellsNow:] ()
#2 0x000000018f6e45c0 in -[UICollectionView layoutSubviews] ()
#3 0x000000018f685738 in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#4 0x000000018cb4e40c in -[CALayer layoutSublayers] ()
#5 0x000000018cb430e8 in CA::Layer::layout_if_needed(CA::Transaction*) ()
#6 0x000000018f69a1a8 in -[UIView(Hierarchy) layoutBelowIfNeeded] ()
#7 0x000000010011a780 in -[ProProfileGalleryCell systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:] at /Users/mhollingshead/git/melon/ios/Melon/Views/CellViews/ProProfileCells/ProProfileGalleryCell.m:149
within the layoutAttributesForElementsInRect: call I sometimes see:
#0 0x000000011476e288 in pthread_setspecific ()
#1 0x00000001134c271f in objc_retainAutoreleasedReturnValue ()
or
#0 0x0000000110e7c9e7 in -[NSConcreteMapTable objectForKey:] ()