最近在弄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];
这样就可以了