UICollectionViewLayoutAttributes

UICollectionViewLayoutAttributes

我的ios应用程序崩溃,但出现以下异常:

void HandleExceptions(NSException *__strong):875 ERROR: uncaught exception: no UICollectionViewLayoutAttributes instance for -layoutAttributesForDecorationViewOfKindOfKind: ColorDecoratorView at path <NSIndexPath: 0x7d843ec0> {length = 3, path = 3 - 0}

您能否告诉我“-layoutAttributesForDecorationViewOfKindOfKind没有UICollectionViewLayoutAttributes实例”的含义是什么?我应该在哪里寻找麻烦去解决呢?

我已经暗示了这种方法:
   - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)decorationViewKind atIndexPath:(NSIndexPath *)indexPath

但是旋转屏幕时出现以下异常:
uncaught exception: layout attributes for supplementary item at index path (<NSIndexPath: 0x79ef2c80> {length = 2, path = 1 - 0}) changed from <UICollectionViewLayoutAttributes: 0x82e76830> index path: (<NSIndexPath: 0x79ebf750> {length = 2, path = 1 - 0}); element kind: (ColorDecoratorView); frame = (72 2513; 293.333 252);  to <UICollectionViewLayoutAttributes: 0x79ef9380> index path: (<NSIndexPath: 0x79ef2c80> {length = 2, path = 1 - 0}); element kind: (ColorDecoratorView); frame = (0 825; 1024 -327);  without invalidating the layout

谢谢。

最佳答案

您正在实施此方法吗?
- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)decorationViewKind atIndexPath:(NSIndexPath *)indexPath
返回值为A layout attributes object containing the information to apply to the decoration view.
我会说实现此方法。像这样的东西
UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:decorationViewKind withIndexPath:indexPath];attrs.frame = cgrectmake (x,x,x,x);return attrs;
看起来您的单元格正在从集合视图中请求一些layoutAttributes。
NSIndexPath似乎是[L = 3,路径= 3];

获取indexPath.row并在cellForRowAtIndexPath中进一步调查。

10-01 16:23