Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Tests crash with estimatedItemSize on Collection View Flow Layout - EXC_ARITHMETIC

I have a UICollectionViewFlowLayout with an estimatedItemSize set.

When I run my application, everything works fine, but in my unit tests, I get an EXC_ARITHMETIC crash every time I hit collectionView:dequeueReusableCellWithReuseIdentifier:.

I know this is due to my estimatedItemSize as removing it fixes the crash.

Does anyone have any idea why this is happening?

Thanks

like image 758
AnthonyMDev Avatar asked Nov 09 '22 17:11

AnthonyMDev


1 Answers

I have the same problem with UICollectionViewFlowLayout and estimatedItemSize. I filed a radar and Apple closed it as a duplicate with no further suggestions as a workaround. My best guess and research thus far indicates that self-sizing cells are fundamentally broken on iOS 8 / 9.

Try random values of estimatedItemSize. For me, setting sizes that closely match the resulting size of your cells cause a crash but sizes much smaller than your cells (1,1) for example do not crash.

I know this is not what you want to hear but it might be the only option until Apple fixes UICollectionView.

like image 161
wasabi Avatar answered Nov 14 '22 21:11

wasabi