最近在項(xiàng)目中遇到一個(gè)問(wèn)題,我自定義布局模仿喵街的時(shí)候一直報(bào)一個(gè)警告,下面是打?。?/p>
**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**
谷歌了很久一直沒(méi)有找到答案,最后通過(guò)如下方式解決了問(wèn)題,在此記錄一下:
原來(lái)的方法是:
NSArray *array = [super layoutAttributesForElementsInRect:correctRect];
將上面的方法改為:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *original = [super layoutAttributesForElementsInRect:correctRect];
NSArray *array = [[NSArray alloc]initWithArray:original copyItems:YES]; }
就搞定了