最近在项目中遇到一个问题,我自定义布局模仿喵街的时候一直报一个警告,下面是打印:
**UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} - cached value: {{0, -170}, {414, 240}}; expected value: {{0, 0}, {414, 0}}**
**2016-05-24 20:02:26.808 SquareTest[4974:409557] This is likely occurring because the flow layout subclass YYSliderViewLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them**
谷歌了很久一直没有找到答案,最后通过如下方式解决了问题,在此记录一下:
原来的方法是:
NSArray *array = [super layoutAttributesForElementsInRect:correctRect];
将上面的方法改为:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *original = [super layoutAttributesForElementsInRect:correctRect];
NSArray *array = [[NSArray alloc]initWithArray:original copyItems:YES]; }
就搞定了