小弟我用故事版上弄了一个UICollectionview,自定义flowlayout;
设定cell的size为(401,148)
当我在它的代理方法里面取出cell的时候(UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"picture" forIndexPath:indexPath];)
打印发现前4个cell的size为(50,50);后面显示的cell的size都正常。请问这是什么原因。下面是xcode给我的提示:
Logging only once for UICollectionViewFlowLayout cache mismatched frame
UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} - cached value: {{-72.498976843927437, 14.090629367551388}, {447.84976661094447, 189.53807857184424}}; expected value: {{0, 35}, {401, 148}}
This is likely occurring because the flow layout subclass myFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them求大神帮帮忙!!!!

解决方案 »

  1.   

    自定义flowlayout需要在
    - (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{
        NSArray * original   = [super layoutAttributesForElementsInRect:rect];
        NSArray * array = [[NSArray alloc] initWithArray:original copyItems:YES];
        return array;
    }
    返回所有[super layoutAttributesForElementsInRect:rect]的拷贝