@@ -18,8 +18,10 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
18
18
19
19
NSMutableDictionary *rowCollections = [NSMutableDictionary new ];
20
20
21
+ id <UICollectionViewDelegateFlowLayout> flowDelegate = (id <UICollectionViewDelegateFlowLayout>) [[self collectionView ] delegate ];
22
+ BOOL delegateSupportsInteritemSpacing = [flowDelegate respondsToSelector: @selector (collectionView:layout:minimumInteritemSpacingForSectionAtIndex: )];
23
+
21
24
// Collect attributes by their midY coordinate.. i.e. rows!
22
-
23
25
for (UICollectionViewLayoutAttributes *itemAttributes in superAttributes)
24
26
{
25
27
// Normalize the midY to others in the row
@@ -53,21 +55,15 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
53
55
NSInteger itemsInRow = [itemAttributesCollection count ];
54
56
55
57
// x-x-x-x ... sum up the interim space
56
- CGFloat interitemSpacing;
57
- if ([[[self collectionView ] delegate ] respondsToSelector: @selector (collectionView:layout:minimumInteritemSpacingForSectionAtIndex: )])
58
+ CGFloat interitemSpacing = [self minimumInteritemSpacing ];
59
+
60
+ // Check for delegate support
61
+ if (delegateSupportsInteritemSpacing && itemsInRow > 0 )
58
62
{
59
- NSUInteger section;
60
- if (itemsInRow) {
61
- UICollectionView * collectionView = [self collectionView ];
62
- id <UICollectionViewDelegateFlowLayout> delegate = [collectionView delegate ];
63
-
64
- // assuming rows never contain elements from more than one section
65
- interitemSpacing = [delegate collectionView: collectionView layout: self minimumInteritemSpacingForSectionAtIndex: [[itemAttributesCollection[0 ] indexPath ] section ]];
66
- } else {
67
- interitemSpacing = 0 ; // probably a sensible default?
68
- }
69
- } else {
70
- interitemSpacing = [self minimumInteritemSpacing ];
63
+ NSInteger section = [[itemAttributesCollection[0 ] indexPath ] section ];
64
+ interitemSpacing = [flowDelegate collectionView: self .collectionView
65
+ layout: self
66
+ minimumInteritemSpacingForSectionAtIndex: section];
71
67
}
72
68
73
69
CGFloat aggregateInteritemSpacing = interitemSpacing * (itemsInRow -1 );
0 commit comments