我的iOS应用程序崩溃,出现以下异常:
void HandleExceptions(NSException *__strong):875 ERROR: uncaught exception: no UICollectionViewLayoutAttributes instance for -layoutAttributesForDecorationViewOfKindOfKind: ColorDecoratorView at path <NSIndexPath: 0x7d843ec0> {length = 3, path = 3 - 0}
你能告诉我"没有UICollectionViewLayoutAttributes实例for -layoutAttributesForDecorationViewOfKindOfKindKind"是什么意思吗?我应该在哪里进行故障排除?
我已经实施了这种方法:
- (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
谢谢。
你在实现这个medthod吗?
- (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;
看起来像您的单元格正在从集合视图中请求一些布局属性。NSIndexPath 似乎是 [L=3, path = 3];
获取 indexPath.row 并在 cellForRowAtIndexPath 中进一步调查。