重寫UICollectionLayout報錯解決

報錯

Logging only once for UICollectionViewFlowLayout cache mismatched frame

 UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000001c00016> {length = 2, path = 0 - 14} - cached value: {{257, 748}, {100, 50}}; expected value: {{0, 714}, {100, 100}}

This is likely occurring because the flow layout subclass AMGrowFootFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

解決

- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{

    NSArray *orginal = [super layoutAttributesForElementsInRect:rect];
    NSArray *attrArr = [[NSArray alloc] initWithArray:orginal copyItems:YES];
    // 在這裏面修改了UICollectionViewLayoutAttributes屬性,必須操作對象副本,所以深拷貝一份。
    return attrArr;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章