您的位置:首页 > 产品设计 > UI/UE

UICollectionViewFlowLayout has cached frame mismatch for index path

2015-10-25 11:07 344 查看
在升级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:方法返回的数组扔到这个方法中,并且使用返回后的数组就行了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: