我正在尝试在UICollectionViewController
中设置iOS 8自动调整大小的单元格:
我使用StoryBoards创建了一个基本设计,并在其中设计了一个带有标签的UICollectionViewCell,该标签被限制在单元格的边界内。然后,我将该单元格的标签链接到单元格类,以便能够通过编程访问它。
如果不指定estimatedItemSize
,一切都正常(当然除了自动调整大小)。
当我这样指定estimatedItemSize
时:
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionViewLayout;
layout.estimatedItemSize = CGSizeMake(100.0f, 30.0f);
}
应用程序崩溃并显示以下错误信息:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item width must be less than the width of the UICollectionView minus the section insets left and right values.
Please check the values return by the delegate.
我认为,我在错误的位置设置了 estimatedItemSize
,或者,如果我已经在故事板中设置了指定项大小,那么它会与估计大小冲突。