1. 程式人生 > >Logging only once for UICollectionViewFlowLayout cache mismatched frame

Logging only once for UICollectionViewFlowLayout cache mismatched frame

最近在弄UIcollectionView的時候,終端出現了這個警告:上網查了半天終於找到了原因:
參考:link
下面是終端報的錯:
Logging only once for UICollectionViewFlowLayout cache mismatched frame
2016-05-13 11:50:35.420 **[72165:1535091] UICollectionViewFlowLayout has cached frame mismatch for index path {length = 2, path = 0 - 0} - cached value: {{-6.3377234115838803, -0.0029442708129181483}, {387.39080917331364, 553.96885150458877}}; expected value: {{8, 20.5}, {358.71536235014594, 512.96296296296293}}
2016-05-13 11:50:35.420 **

[72165:1535091] This is likely occurring because the flow layout subclass WJMCollectionViewFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

解決方法是將:

NSArray* original = [super layoutAttributesForElementsInRect:myrect];

替換為:

NSArray *original = [[NSArray
alloc]initWithArray:[super layoutAttributesForElementsInRect:myrect] copyItems:YES];

這樣就可以了