Citrrus / MBContactPicker

iOS7 Styled Contact Picker Library that uses a UICollectionView
MIT License
501 stars 60 forks source link

UICollectionViewFlowLayout warning #97

Open ianiv opened 8 years ago

ianiv commented 8 years ago

The first time a letter is typed, the following warning is printed to the console:

Logging only once for UICollectionViewFlowLayout cache mismatched frame
UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1} - cached value: {{54, 0}, {311, 31}}; expected value: {{59, 0}, {50, 31}}
This is likely occurring because the flow layout subclass MBContactCollectionViewFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

Making a copy of the attributes returned by layoutAttributesForElementsInRect and layoutAttributesForItemAtIndexPath solves the problem.

tcheard commented 8 years ago

Changing MBContactCollectionViewFlowLayout.m:21 from NSArray* attributesToReturn = [super layoutAttributesForElementsInRect:rect]; to NSArray* attributesToReturn = [[NSArray alloc] initWithArray:[super layoutAttributesForElementsInRect:rect] copyItems:YES];

and

MBContactCollectionViewFlowLayout.m:37 from UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; to UICollectionViewLayoutAttributes* currentItemAttributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];

fixes the warnings for me.