Skip to content

Commit f82b11e

Browse files
committed
Fix cached frame mismatch warning (issue mokagio#4)
1 parent 8e9cc8c commit f82b11e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,20 @@ @implementation UICollectionViewLeftAlignedLayout
4444
#pragma mark - UICollectionViewLayout
4545

4646
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
47-
NSArray* attributesToReturn = [super layoutAttributesForElementsInRect:rect];
48-
for (UICollectionViewLayoutAttributes* attributes in attributesToReturn) {
49-
if (nil == attributes.representedElementKind) {
50-
NSIndexPath* indexPath = attributes.indexPath;
51-
attributes.frame = [self layoutAttributesForItemAtIndexPath:indexPath].frame;
47+
NSMutableArray* attributesToReturn = [NSMutableArray array];
48+
for (UICollectionViewLayoutAttributes* attributes in [super layoutAttributesForElementsInRect:rect]) {
49+
UICollectionViewLayoutAttributes* attributesCopy = [attributes copy];
50+
if (nil == attributesCopy.representedElementKind) {
51+
NSIndexPath* indexPath = attributesCopy.indexPath;
52+
attributesCopy.frame = [self layoutAttributesForItemAtIndexPath:indexPath].frame;
5253
}
54+
[attributesToReturn addObject:attributesCopy];
5355
}
5456
return attributesToReturn;
5557
}
5658

5759
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
58-
UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];
60+
UICollectionViewLayoutAttributes* currentItemAttributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy];
5961
UIEdgeInsets sectionInset = [self evaluatedSectionInsetForItemAtIndex:indexPath.section];
6062

6163
BOOL isFirstItemInSection = indexPath.item == 0;

0 commit comments

Comments
 (0)