Clean up caching of collection view delegate selectors on the inspector

This commit is contained in:
Levi McCallum 2015-10-21 23:14:54 -07:00
parent 084d60883b
commit e8ce7fcbb2
3 changed files with 12 additions and 7 deletions

View File

@ -334,7 +334,7 @@ static BOOL _isInterceptedSelector(SEL sel)
_asyncDelegateImplementsInsetSection = ([_asyncDelegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)] ? 1 : 0);
}
[_flowLayoutInspector cacheSelectorsForCollectionView:self];
[_layoutInspector didChangeCollectionViewDelegate:asyncDelegate];
}
- (void)setCollectionViewLayout:(UICollectionViewLayout *)collectionViewLayout

View File

@ -11,6 +11,7 @@
#import <AsyncDisplayKit/ASDimension.h>
@class ASCollectionView;
@protocol ASCollectionViewDelegate;
@protocol ASCollectionViewLayoutInspecting <NSObject>
@ -29,6 +30,13 @@
*/
- (NSUInteger)collectionView:(ASCollectionView *)collectionView supplementaryNodesOfKind:(NSString *)kind inSection:(NSUInteger)section;
/**
* Allow the inspector to respond to delegate changes.
*
* @discussion A great time to update perform selector caches!
*/
- (void)didChangeCollectionViewDelegate:(id<ASCollectionViewDelegate>)delegate;
@end
@interface ASCollectionViewFlowLayoutInspector : NSObject <ASCollectionViewLayoutInspecting>
@ -37,6 +45,4 @@
- (instancetype)initWithCollectionView:(ASCollectionView *)collectionView flowLayout:(UICollectionViewFlowLayout *)flowLayout;
- (void)cacheSelectorsForCollectionView:(ASCollectionView *)collectionView;
@end

View File

@ -30,19 +30,18 @@
}
if (self != nil) {
[self cacheSelectorsForCollectionView:collectionView];
[self didChangeCollectionViewDelegate:collectionView.asyncDelegate];
_layout = flowLayout;
}
return self;
}
- (void)cacheSelectorsForCollectionView:(ASCollectionView *)collectionView
- (void)didChangeCollectionViewDelegate:(id<ASCollectionViewDelegate>)delegate;
{
if (collectionView == nil) {
if (delegate == nil) {
_delegateImplementsReferenceSizeForHeader = nil;
_delegateImplementsReferenceSizeForFooter = nil;
} else {
id<ASCollectionViewDelegateFlowLayout> delegate = [self delegateForCollectionView:collectionView];
_delegateImplementsReferenceSizeForHeader = [delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForHeaderInSection:)];
_delegateImplementsReferenceSizeForFooter = [delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForFooterInSection:)];
}