UICollectionViewFlowLayout has cached frame mismatch for index path

来源:互联网 发布:it管培生 编辑:程序博客网 时间:2024/05/18 23:27

在升级XCode7.0使用UICollectionViewLayout进行自定义布局时,调试台会出现以下的警告打印。

UICollectionViewFlowLayout has cached frame mismatch for index path {length = 2, path = 0 - 0} - cached value: {{122, 15}, {170, 170}}; expected value: {{157, 50}, {100, 100}}
This is likely occurring because the flow layout subclass LineLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

这个警告来源主要是在使用layoutAttributesForElementsInRect:方法返回的数组时,没有使用该数组的拷贝对象,而是直接使用了该数组。解决办法对该数组进行拷贝,并且是深拷贝。拷贝代码如下:

- (NSArray *)deepCopyWithArray:(NSArray *)array{    NSMutableArray *copys = [NSMutableArray arrayWithCapacity:array.count];    for (UICollectionViewLayoutAttributes *attris in array) {        [copys addObject:[attris copy]];    }    return copys;}

将layoutAttributesForElementsInRect:方法返回的数组扔到这个方法中,并且使用返回后的数组就行了。

1 0
原创粉丝点击