From f39da700afb4eae1ffe3d6beaeecc0a17d5bc08c Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Tue, 18 Apr 2017 20:15:39 +0100 Subject: [PATCH] Ensure a supplementary view is of kind _ASCollectionReusableView before setting its layoutAttributes --- Source/ASCollectionView.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index f8b466bc7..0e6b95c65 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -1118,9 +1118,10 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:( - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(_ASCollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { + // Since _ASCollectionReusableView is not available for subclassing, comparing the classes is faster than isKindOfClass: // This is a safeguard similar to the behavior for cells in -[ASCollectionView collectionView:willDisplayCell:forItemAtIndexPath:] // It ensures _ASCollectionReusableView receives layoutAttributes and calls applyLayoutAttributes. - if (view.layoutAttributes == nil) { + if (([view class] == [_ASCollectionReusableView class]) && (view.layoutAttributes == nil)) { view.layoutAttributes = [collectionView layoutAttributesForSupplementaryElementOfKind:elementKind atIndexPath:indexPath]; }