UIFlowLayoutSection.updateEstimatedSizeForSection中的EXC_ARITHMETIC

时间:2016-02-05 13:07:18

标签: ios swift uikit

尝试显示UICollectionView时,我在模拟器中收到以下错误:

    UIKit`-[_UIFlowLayoutSection updateEstimatedSizeForSection:]:
    ...
    0x106d32858 <+582>:  movq   0x416909(%rip), %rcx      ; _UIFlowLayoutSection._validItemRange
    0x106d3285f <+589>:  xorl   %edx, %edx
->  0x106d32861 <+591>:  divq   0x8(%rcx,%rbx) 

Thread 1: EXC_ARITHMETIC (code=EXC_I386_DIV, subcode=0x0)

我已正确设置估计的单元格大小,并且还将集合视图高度设置为大于单元格高度。所有插入都设置为0.但在崩溃之前,我仍然收到以下警告:

the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
Please check the values return by the delegate.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fe65d28b7c0>, and it is attached to <UICollectionView: 0x7fe65c859000; frame = (5 63; 365 110); clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x7fe65d28bea0>; animations = { opacity=<CABasicAnimation: 0x7fe65d702fd0>; bounds.origin=<CABasicAnimation: 0x7fe65d704610>; bounds.size=<CABasicAnimation: 0x7fe65d704630>; }; layer = <CALayer: 0x7fe65d03a0b0>; contentOffset: {0, 0}; contentSize: {1798, 110}> collection view layout: <UICollectionViewFlowLayout: 0x7fe65d28b7c0>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我通过在集合视图单元格中将UIImageView大小设置为固定来修复此问题,而不是使用约束将图像视图拉伸到单元格的大小。

这很奇怪,因为UICollectionView不应该将单元格缩放到大于dataSource中返回的大小。另外,当它具有clipsToBounds = true时,UIImageView大小与单元格大小有什么关系?只要单元格本身具有正确的大小,UICollectionView就不应该知道单元格包含哪些视图。