From e646fbf1f309b820934979c17b20cd000f1c5737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Misi=C5=ABra?= Date: Sun, 14 Dec 2014 14:51:38 +0200 Subject: [PATCH 01/10] Implemented "-visibleSupplementaryViews" and "-visibleSupplementaryViewsForKind:" methods --- .../JNWCollectionViewFramework.h | 6 ++++++ .../JNWCollectionViewFramework.m | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/JNWCollectionView/JNWCollectionViewFramework.h b/JNWCollectionView/JNWCollectionViewFramework.h index 6f28e57..7566c90 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.h +++ b/JNWCollectionView/JNWCollectionViewFramework.h @@ -235,6 +235,12 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) { /// previously registered in -registerClass:forSupplementaryViewOfKind:reuseIdentifier:. - (JNWCollectionViewReusableView *)supplementaryViewForKind:(NSString *)kind reuseIdentifier:(NSString *)reuseIdentifier inSection:(NSInteger)section; +/// Returns an array of all the currently visible supplementary views. The cells are not guaranteed to be in any order. +- (NSArray *)visibleSupplementaryViews; + +/// Returns an array of all the currently visible supplementary views for the specified kind. The cells are not guaranteed to be in any order. +- (NSArray *)visibleSupplementaryViewsForKind:(NSString *)kind; + /// Returns an array of all the currently visible cells. The cells are not guaranteed to be in any order. - (NSArray *)visibleCells; diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index b046b03..0b863d3 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -394,6 +394,27 @@ - (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point { return nil; } +- (NSArray *)visibleSupplementaryViews +{ + return self.visibleSupplementaryViewsMap.allValues; +} + +- (NSArray *)visibleSupplementaryViewsForKind:(NSString *)kind +{ + NSArray *allKeys = self.visibleSupplementaryViewsMap.allKeys; + NSMutableArray *visibleSupplementaryViews = [[NSMutableArray alloc] initWithCapacity:allKeys.count]; + + for (NSString *key in allKeys) + { + NSString *supplementaryViewKind = [self kindForSupplementaryViewIdentifier:key]; + if ([kind isEqualToString:supplementaryViewKind]) + { + [visibleSupplementaryViews addObject:self.visibleSupplementaryViewsMap[key]]; + } + } + return visibleSupplementaryViews; +} + - (NSArray *)visibleCells { return self.visibleCellsMap.allValues; } From 38fa310b3385456e160c1c01f082111809b486cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Misi=C5=ABra?= Date: Sun, 14 Dec 2014 14:56:02 +0200 Subject: [PATCH 02/10] Added willDisplaySupplementaryView and didEndDisplayingSupplementaryView messages to JNWCollectionViewDelegate protocol --- .../JNWCollectionViewFramework.h | 4 +++ .../JNWCollectionViewFramework.m | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/JNWCollectionView/JNWCollectionViewFramework.h b/JNWCollectionView/JNWCollectionViewFramework.h index 7566c90..2288ece 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.h +++ b/JNWCollectionView/JNWCollectionViewFramework.h @@ -115,6 +115,10 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) { /// back into the reuse queue. - (void)collectionView:(JNWCollectionView *)collectionView didEndDisplayingCell:(JNWCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath; +- (void)collectionView:(JNWCollectionView *)collectionView willDisplaySupplementaryView:(JNWCollectionViewReusableView *)supplementaryView ofKind:(NSString *)kind forsection:(NSInteger)section; + +- (void)collectionView:(JNWCollectionView *)collectionView didEndDisplayingSupplementaryView:(JNWCollectionViewReusableView *)supplementaryView ofKind:(NSString *)kind forsection:(NSInteger)section; + @end #pragma mark Reloading and customizing diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index 0b863d3..999bb99 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -49,6 +49,8 @@ @interface JNWCollectionView() { unsigned int delegateDidDoubleClick:1; unsigned int delegateDidRightClick:1; unsigned int delegateDidEndDisplayingCell:1; + unsigned int delegateWillDisplaySupplementaryView:1; + unsigned int delegateDidEndDisplayingSupplementaryView:1; unsigned int wantsLayout; } _collectionViewFlags; @@ -139,6 +141,8 @@ - (void)setDelegate:(id)delegate { _collectionViewFlags.delegateDidDoubleClick = [delegate respondsToSelector:@selector(collectionView:didDoubleClickItemAtIndexPath:)]; _collectionViewFlags.delegateDidRightClick = [delegate respondsToSelector:@selector(collectionView:didRightClickItemAtIndexPath:)]; _collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)]; + _collectionViewFlags.delegateWillDisplaySupplementaryView = [delegate respondsToSelector:@selector(collectionView:willDisplaySupplementaryView:ofKind:forsection:)]; + _collectionViewFlags.delegateDidEndDisplayingSupplementaryView = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingSupplementaryView:ofKind:forsection:)]; } - (void)setDataSource:(id)dataSource { @@ -354,6 +358,17 @@ - (void)resetAllCellsAndSupplementaryViews { } } [self.visibleCellsMap removeAllObjects]; + + if (_collectionViewFlags.delegateDidEndDisplayingSupplementaryView) + { + [self.visibleSupplementaryViewsMap enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + + NSInteger section = [self sectionForSupplementaryLayoutIdentifier:key]; + JNWCollectionViewReusableView *supplementaryView = obj; + [self.delegate collectionView:self didEndDisplayingSupplementaryView:supplementaryView ofKind:supplementaryView.kind forsection:section]; + + }]; + } [self.visibleSupplementaryViewsMap removeAllObjects]; // Remove any cells or views that might be added to the document view. @@ -823,6 +838,11 @@ - (void)layoutSupplementaryViewsWithRedraw:(BOOL)needsVisibleRedraw { [view removeFromSuperview]; [self enqueueReusableSupplementaryView:view ofKind:view.kind withReuseIdentifier:view.reuseIdentifier]; + + if (_collectionViewFlags.delegateDidEndDisplayingSupplementaryView) + { + [self.delegate collectionView:self didEndDisplayingSupplementaryView:view ofKind:view.kind forsection:[self sectionForSupplementaryLayoutIdentifier:layoutIdentifier]]; + } } // Add new views @@ -838,6 +858,12 @@ - (void)layoutSupplementaryViewsWithRedraw:(BOOL)needsVisibleRedraw { JNWCollectionViewLayoutAttributes *attributes = [self.collectionViewLayout layoutAttributesForSupplementaryItemInSection:section kind:kind]; view.frame = attributes.frame; view.alphaValue = attributes.alpha; + + if (_collectionViewFlags.delegateWillDisplaySupplementaryView) + { + [self.delegate collectionView:self willDisplaySupplementaryView:view ofKind:view.kind forsection:[self sectionForSupplementaryLayoutIdentifier:layoutIdentifier]]; + } + [self.documentView addSubview:view]; self.visibleSupplementaryViewsMap[layoutIdentifier] = view; From e952333fa508c0cad4b2358588630abd2ae74f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Misi=C5=ABra?= Date: Mon, 15 Dec 2014 10:27:45 +0200 Subject: [PATCH 03/10] Added descriptions to new JNWCollectionViewDelegate methods --- JNWCollectionView/JNWCollectionViewFramework.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/JNWCollectionView/JNWCollectionViewFramework.h b/JNWCollectionView/JNWCollectionViewFramework.h index 2288ece..ce39fc6 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.h +++ b/JNWCollectionView/JNWCollectionViewFramework.h @@ -115,8 +115,10 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) { /// back into the reuse queue. - (void)collectionView:(JNWCollectionView *)collectionView didEndDisplayingCell:(JNWCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath; +/// Tells the delegate that supplementary view will be added to document view. - (void)collectionView:(JNWCollectionView *)collectionView willDisplaySupplementaryView:(JNWCollectionViewReusableView *)supplementaryView ofKind:(NSString *)kind forsection:(NSInteger)section; +/// Tells the delegate that supplementary view was removed from document view. - (void)collectionView:(JNWCollectionView *)collectionView didEndDisplayingSupplementaryView:(JNWCollectionViewReusableView *)supplementaryView ofKind:(NSString *)kind forsection:(NSInteger)section; @end From 0e1f15a30b90061056314b2fa77c52a69c1b63e7 Mon Sep 17 00:00:00 2001 From: Spencer Williams Date: Wed, 10 Dec 2014 14:57:51 -0800 Subject: [PATCH 04/10] adds shouldScroll to delegate --- JNWCollectionView/JNWCollectionViewFramework.h | 3 +++ JNWCollectionView/JNWCollectionViewFramework.m | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/JNWCollectionView/JNWCollectionViewFramework.h b/JNWCollectionView/JNWCollectionViewFramework.h index ce39fc6..36a84b6 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.h +++ b/JNWCollectionView/JNWCollectionViewFramework.h @@ -108,6 +108,9 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) { /// Tells the delegate that the item at the specified index path has been right-clicked. - (void)collectionView:(JNWCollectionView *)collectionView didRightClickItemAtIndexPath:(NSIndexPath *)indexPath; +/// Asks the delegate if the item at the specified index path should be scrolled to. +- (BOOL)collectionView:(JNWCollectionView *)collectionView shouldScrollToItemAtIndexPath:(NSIndexPath *)indexPath; + /// Tells the delegate that the specified index path has been scrolled to. - (void)collectionView:(JNWCollectionView *)collectionView didScrollToItemAtIndexPath:(NSIndexPath *)indexPath; diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index 999bb99..b7fcc46 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -45,6 +45,7 @@ @interface JNWCollectionView() { unsigned int delegateDidSelect:1; unsigned int delegateShouldDeselect:1; unsigned int delegateDidDeselect:1; + unsigned int delegateShouldScroll:1; unsigned int delegateDidScroll:1; unsigned int delegateDidDoubleClick:1; unsigned int delegateDidRightClick:1; @@ -140,7 +141,9 @@ - (void)setDelegate:(id)delegate { _collectionViewFlags.delegateDidDeselect = [delegate respondsToSelector:@selector(collectionView:didDeselectItemAtIndexPath:)]; _collectionViewFlags.delegateDidDoubleClick = [delegate respondsToSelector:@selector(collectionView:didDoubleClickItemAtIndexPath:)]; _collectionViewFlags.delegateDidRightClick = [delegate respondsToSelector:@selector(collectionView:didRightClickItemAtIndexPath:)]; - _collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)]; + _collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)]; + _collectionViewFlags.delegateShouldScroll = [delegate respondsToSelector:@selector(collectionView:shouldScrollToItemAtIndexPath:)]; + _collectionViewFlags.delegateDidScroll = [delegate respondsToSelector:@selector(collectionView:didScrollToItemAtIndexPath:)]; _collectionViewFlags.delegateWillDisplaySupplementaryView = [delegate respondsToSelector:@selector(collectionView:willDisplaySupplementaryView:ofKind:forsection:)]; _collectionViewFlags.delegateDidEndDisplayingSupplementaryView = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingSupplementaryView:ofKind:forsection:)]; } @@ -148,7 +151,6 @@ - (void)setDelegate:(id)delegate { - (void)setDataSource:(id)dataSource { _dataSource = dataSource; _collectionViewFlags.dataSourceNumberOfSections = [dataSource respondsToSelector:@selector(numberOfSectionsInCollectionView:)]; - _collectionViewFlags.delegateDidScroll = [dataSource respondsToSelector:@selector(collectionView:didScrollToItemAtIndexPath:)]; _collectionViewFlags.dataSourceViewForSupplementaryView = [dataSource respondsToSelector:@selector(collectionView:viewForSupplementaryViewOfKind:inSection:)]; NSAssert(dataSource == nil || [dataSource respondsToSelector:@selector(collectionView:numberOfItemsInSection:)], @"data source must implement collectionView:numberOfItemsInSection"); @@ -522,6 +524,10 @@ - (NSArray *)indexPathsForVisibleItems { } - (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(JNWCollectionViewScrollPosition)scrollPosition animated:(BOOL)animated { + if (_collectionViewFlags.delegateShouldScroll && ![self.delegate collectionView:self shouldScrollToItemAtIndexPath:indexPath]) { + return; + } + CGRect rect = [self rectForItemAtIndexPath:indexPath]; CGRect visibleRect = self.documentVisibleRect; @@ -987,7 +993,7 @@ - (void)selectItemAtIndexPath:(NSIndexPath *)indexPath selectionType:(JNWCollectionViewSelectionType)selectionType { if (indexPath == nil) return; - + NSMutableSet *indexesToSelect = [NSMutableSet set]; if (selectionType == JNWCollectionViewSelectionTypeSingle) { From 4cced8ef0cb6793c77f5e50a911bb5193f9bd30a Mon Sep 17 00:00:00 2001 From: Spencer Williams Date: Fri, 12 Dec 2014 15:22:42 -0800 Subject: [PATCH 05/10] use tabs, not spaces --- JNWCollectionView/JNWCollectionViewFramework.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index b7fcc46..9779caf 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -45,7 +45,7 @@ @interface JNWCollectionView() { unsigned int delegateDidSelect:1; unsigned int delegateShouldDeselect:1; unsigned int delegateDidDeselect:1; - unsigned int delegateShouldScroll:1; + unsigned int delegateShouldScroll:1; unsigned int delegateDidScroll:1; unsigned int delegateDidDoubleClick:1; unsigned int delegateDidRightClick:1; From 092dd51ed46afea7e6520aea51ebdb53b5fe865a Mon Sep 17 00:00:00 2001 From: Jonathan Willing Date: Tue, 16 Dec 2014 18:39:55 -0600 Subject: [PATCH 06/10] update podspec --- JNWCollectionView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JNWCollectionView.podspec b/JNWCollectionView.podspec index c15c51f..1a987e8 100644 --- a/JNWCollectionView.podspec +++ b/JNWCollectionView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "JNWCollectionView" - s.version = "1.2" + s.version = "1.3" s.summary = "A highly customizable and performant collection view for the Mac." s.homepage = "https://github.com/jwilling/JNWCollectionView" s.screenshots = "http://jwilling.com/drop/github/JNWCollectionView.png" From 659e56174e27f093ae3515cc340a5d529ab31235 Mon Sep 17 00:00:00 2001 From: Jonathan Willing Date: Tue, 16 Dec 2014 18:52:41 -0600 Subject: [PATCH 07/10] silence ARC warning --- JNWCollectionView.xcodeproj/project.pbxproj | 2 +- JNWCollectionView/JNWCollectionViewFramework.m | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/JNWCollectionView.xcodeproj/project.pbxproj b/JNWCollectionView.xcodeproj/project.pbxproj index d87ac59..b56a6a2 100644 --- a/JNWCollectionView.xcodeproj/project.pbxproj +++ b/JNWCollectionView.xcodeproj/project.pbxproj @@ -446,7 +446,7 @@ ABB023E8170791D300537A92 /* Project object */ = { isa = PBXProject; attributes = { - LastTestingUpgradeCheck = 0510; + LastTestingUpgradeCheck = 0610; LastUpgradeCheck = 0500; ORGANIZATIONNAME = AppJon; }; diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index 9779caf..808d0d9 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -77,6 +77,8 @@ @interface JNWCollectionView() { @property (nonatomic, strong) NSMutableDictionary *supplementaryViewClassMap; // { "kind/identifier" : class } @property (nonatomic, strong) NSMutableDictionary *supplementaryViewNibMap; // { "kind/identifier" : nib } +@property (nonatomic, strong) NSView *documentView; + @end @implementation JNWCollectionView From 65c9ed0fe179b0cb4dfc64c8b24ca6715646fa3a Mon Sep 17 00:00:00 2001 From: BJ Homer Date: Fri, 19 Dec 2014 11:37:53 -0700 Subject: [PATCH 08/10] Don't override -[NSIndexPath isEqual:] Index paths are used with other Cocoa classes, and may contain more than 2 items. The default implementation of -isEqual should already handle the 2-item case correctly. --- JNWCollectionView/NSIndexPath+JNWAdditions.m | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/JNWCollectionView/NSIndexPath+JNWAdditions.m b/JNWCollectionView/NSIndexPath+JNWAdditions.m index 2b89727..8782850 100644 --- a/JNWCollectionView/NSIndexPath+JNWAdditions.m +++ b/JNWCollectionView/NSIndexPath+JNWAdditions.m @@ -35,16 +35,6 @@ - (NSInteger)jnw_item { return [self indexAtPosition:1]; } -- (BOOL)isEqual:(id)object { - if ([object isKindOfClass:NSIndexPath.class]) { - if (self.jnw_section == [(NSIndexPath *)object jnw_section] && self.jnw_item == [(NSIndexPath *)object jnw_item]) { - return YES; - } - } - - return NO; -} - - (NSString *)debugDescription { return [NSString stringWithFormat:@"<%@: %p; section = %ld; item = %ld>", self.class, self, self.jnw_section, self.jnw_item]; } From 6711c49bbc30efde1cd5e2ea00dae208420a3801 Mon Sep 17 00:00:00 2001 From: BJ Homer Date: Fri, 19 Dec 2014 11:42:00 -0700 Subject: [PATCH 09/10] Don't truncate index paths in -debugDescription. If a version that displays the section and item is needed, it should probably have a unique name. Messing with NSIndexPath globally can cause unexpected results elsewhere. --- JNWCollectionView/NSIndexPath+JNWAdditions.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/JNWCollectionView/NSIndexPath+JNWAdditions.m b/JNWCollectionView/NSIndexPath+JNWAdditions.m index 8782850..f1af89c 100644 --- a/JNWCollectionView/NSIndexPath+JNWAdditions.m +++ b/JNWCollectionView/NSIndexPath+JNWAdditions.m @@ -35,8 +35,4 @@ - (NSInteger)jnw_item { return [self indexAtPosition:1]; } -- (NSString *)debugDescription { - return [NSString stringWithFormat:@"<%@: %p; section = %ld; item = %ld>", self.class, self, self.jnw_section, self.jnw_item]; -} - @end From f75e5a47bd72dc2007680780227fe6361d01bcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Misi=C5=ABra?= Date: Mon, 22 Dec 2014 15:00:03 +0200 Subject: [PATCH 10/10] Tabs instead of spaced and brackets in same line. --- .../JNWCollectionViewFramework.m | 65 +++++++++---------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/JNWCollectionView/JNWCollectionViewFramework.m b/JNWCollectionView/JNWCollectionViewFramework.m index 808d0d9..f0074ba 100644 --- a/JNWCollectionView/JNWCollectionViewFramework.m +++ b/JNWCollectionView/JNWCollectionViewFramework.m @@ -50,8 +50,8 @@ @interface JNWCollectionView() { unsigned int delegateDidDoubleClick:1; unsigned int delegateDidRightClick:1; unsigned int delegateDidEndDisplayingCell:1; - unsigned int delegateWillDisplaySupplementaryView:1; - unsigned int delegateDidEndDisplayingSupplementaryView:1; + unsigned int delegateWillDisplaySupplementaryView:1; + unsigned int delegateDidEndDisplayingSupplementaryView:1; unsigned int wantsLayout; } _collectionViewFlags; @@ -146,8 +146,8 @@ - (void)setDelegate:(id)delegate { _collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)]; _collectionViewFlags.delegateShouldScroll = [delegate respondsToSelector:@selector(collectionView:shouldScrollToItemAtIndexPath:)]; _collectionViewFlags.delegateDidScroll = [delegate respondsToSelector:@selector(collectionView:didScrollToItemAtIndexPath:)]; - _collectionViewFlags.delegateWillDisplaySupplementaryView = [delegate respondsToSelector:@selector(collectionView:willDisplaySupplementaryView:ofKind:forsection:)]; - _collectionViewFlags.delegateDidEndDisplayingSupplementaryView = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingSupplementaryView:ofKind:forsection:)]; + _collectionViewFlags.delegateWillDisplaySupplementaryView = [delegate respondsToSelector:@selector(collectionView:willDisplaySupplementaryView:ofKind:forsection:)]; + _collectionViewFlags.delegateDidEndDisplayingSupplementaryView = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingSupplementaryView:ofKind:forsection:)]; } - (void)setDataSource:(id)dataSource { @@ -362,17 +362,16 @@ - (void)resetAllCellsAndSupplementaryViews { } } [self.visibleCellsMap removeAllObjects]; - - if (_collectionViewFlags.delegateDidEndDisplayingSupplementaryView) - { - [self.visibleSupplementaryViewsMap enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - - NSInteger section = [self sectionForSupplementaryLayoutIdentifier:key]; - JNWCollectionViewReusableView *supplementaryView = obj; - [self.delegate collectionView:self didEndDisplayingSupplementaryView:supplementaryView ofKind:supplementaryView.kind forsection:section]; - - }]; - } + + if (_collectionViewFlags.delegateDidEndDisplayingSupplementaryView) { + [self.visibleSupplementaryViewsMap enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + + NSInteger section = [self sectionForSupplementaryLayoutIdentifier:key]; + JNWCollectionViewReusableView *supplementaryView = obj; + [self.delegate collectionView:self didEndDisplayingSupplementaryView:supplementaryView ofKind:supplementaryView.kind forsection:section]; + + }]; + } [self.visibleSupplementaryViewsMap removeAllObjects]; // Remove any cells or views that might be added to the document view. @@ -413,21 +412,17 @@ - (NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point { return nil; } -- (NSArray *)visibleSupplementaryViews -{ +- (NSArray *)visibleSupplementaryViews { return self.visibleSupplementaryViewsMap.allValues; } -- (NSArray *)visibleSupplementaryViewsForKind:(NSString *)kind -{ +- (NSArray *)visibleSupplementaryViewsForKind:(NSString *)kind { NSArray *allKeys = self.visibleSupplementaryViewsMap.allKeys; NSMutableArray *visibleSupplementaryViews = [[NSMutableArray alloc] initWithCapacity:allKeys.count]; - - for (NSString *key in allKeys) - { - NSString *supplementaryViewKind = [self kindForSupplementaryViewIdentifier:key]; - if ([kind isEqualToString:supplementaryViewKind]) - { + + for (NSString *key in allKeys) { + NSString *supplementaryViewKind = [self kindForSupplementaryViewIdentifier:key]; + if ([kind isEqualToString:supplementaryViewKind]) { [visibleSupplementaryViews addObject:self.visibleSupplementaryViewsMap[key]]; } } @@ -846,11 +841,10 @@ - (void)layoutSupplementaryViewsWithRedraw:(BOOL)needsVisibleRedraw { [view removeFromSuperview]; [self enqueueReusableSupplementaryView:view ofKind:view.kind withReuseIdentifier:view.reuseIdentifier]; - - if (_collectionViewFlags.delegateDidEndDisplayingSupplementaryView) - { - [self.delegate collectionView:self didEndDisplayingSupplementaryView:view ofKind:view.kind forsection:[self sectionForSupplementaryLayoutIdentifier:layoutIdentifier]]; - } + + if (_collectionViewFlags.delegateDidEndDisplayingSupplementaryView) { + [self.delegate collectionView:self didEndDisplayingSupplementaryView:view ofKind:view.kind forsection:[self sectionForSupplementaryLayoutIdentifier:layoutIdentifier]]; + } } // Add new views @@ -866,12 +860,11 @@ - (void)layoutSupplementaryViewsWithRedraw:(BOOL)needsVisibleRedraw { JNWCollectionViewLayoutAttributes *attributes = [self.collectionViewLayout layoutAttributesForSupplementaryItemInSection:section kind:kind]; view.frame = attributes.frame; view.alphaValue = attributes.alpha; - - if (_collectionViewFlags.delegateWillDisplaySupplementaryView) - { - [self.delegate collectionView:self willDisplaySupplementaryView:view ofKind:view.kind forsection:[self sectionForSupplementaryLayoutIdentifier:layoutIdentifier]]; - } - + + if (_collectionViewFlags.delegateWillDisplaySupplementaryView) { + [self.delegate collectionView:self willDisplaySupplementaryView:view ofKind:view.kind forsection:[self sectionForSupplementaryLayoutIdentifier:layoutIdentifier]]; + } + [self.documentView addSubview:view]; self.visibleSupplementaryViewsMap[layoutIdentifier] = view;