I have a self sizing collection view and when I call super.layoutSubviews my app crashes since the collection view enters a recursive update loop. This was working fine in iOS 14 and below. But observed it in iOS 15 onwards.
class DynamicCollectionView: UICollectionView {
override var contentSize: CGSize {
didSet {
invalidateIntrinsicContentSize()
}
}
override func layoutSubviews() {
super.layoutSubviews()
if bounds.size != intrinsicContentSize {
invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
return contentSize
}
override func reloadData() {
super.reloadData()
invalidateIntrinsicContentSize()
layoutIfNeeded()
}
}
Crash says:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView (<KPFlagship.SelfSizingCollectionView 0x7f896b260e00>) is stuck in its update/layout loop. This can happen for many reasons, including self-sizing views whose preferred attributes are not returning a consistent size. To debug this issue, check the Console app for logs in the "UICollectionViewRecursion" category.'
layoutSubviews
but I can't say more without code. There is a right way and a wrong way to get cells to self-size in a collection view, and this looks like the wrong way. But again, you didn't ask how to do it; you just complained that your way stopped working. – Yearly