我试图在UICollectionView使用子UICollectionViewFlowLayout类的类中自定义标题的位置(基于堆叠标题的代码松散地显示在此处输入链接描述).
作为最小测试,假设我只想在所有标题的位置添加固定偏移量:
layoutAttributesForElementsInRect以便始终处理所有标题(这可能是问题的原因,我不确定)layoutAttributesForSupplementaryViewOfKind完整的实施包含在本文末尾.
(顺便说一下,我知道在第一步中添加所有标题,包括那些在rect之外的标题,并不是严格说来,但这是一个简单的例子,说明我希望制作的位置更复杂,这会导致所有标题在绘制矩形中显示.)
但是,当我运行代码时,我得到以下内容NSInternalInconsistencyException:
2014-01-15 00:41:50.130 CollectionStackedHeaders[60777:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0x8a7db90> {length = 2, path = 0 - 0})
changed from <UICollectionViewLayoutAttributes: 0x8a7f8b0> index path: (<NSIndexPath: 0x8a7d9c0> {length = 2, path = 0 - 0}); element kind: (UICollectionElementKindSectionHeader); frame = (0 0; 320 50);
to <UICollectionViewLayoutAttributes: 0x8a7fb80> index path: (<NSIndexPath: 0x8a7db90> …Run Code Online (Sandbox Code Playgroud)