From 3c9281c141842970121cff40dbe4e7e65830c8b5 Mon Sep 17 00:00:00 2001 From: jverkoey Date: Tue, 9 Apr 2013 16:18:06 -0700 Subject: [PATCH] [collections] Add shouldAppendObjectClassToReuseIdentifier to the factory. --- src/collections/src/NICollectionViewCellFactory.h | 11 +++++++++++ src/collections/src/NICollectionViewCellFactory.m | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/collections/src/NICollectionViewCellFactory.h b/src/collections/src/NICollectionViewCellFactory.h index 288ae1671..be85cfceb 100644 --- a/src/collections/src/NICollectionViewCellFactory.h +++ b/src/collections/src/NICollectionViewCellFactory.h @@ -157,6 +157,17 @@ _model.delegate = (id)[NICollectionViewCellFactory class]; */ - (BOOL)shouldUpdateCellWithObject:(id)object; +@optional + +/** + * Asks the receiver whether the mapped object class should be appended to the reuse identifier + * in order to create a unique cell.object identifier key. + * + * This is useful when you have a cell that is intended to be used by a variety of different + * objects. + */ ++ (BOOL)shouldAppendObjectClassToReuseIdentifier; + @end /** diff --git a/src/collections/src/NICollectionViewCellFactory.m b/src/collections/src/NICollectionViewCellFactory.m index 198a39a6f..7684789bd 100644 --- a/src/collections/src/NICollectionViewCellFactory.m +++ b/src/collections/src/NICollectionViewCellFactory.m @@ -55,6 +55,11 @@ + (UICollectionViewCell *)cellWithClass:(Class)collectionViewCellClass NSString* identifier = NSStringFromClass(collectionViewCellClass); + if ([collectionViewCellClass respondsToSelector:@selector(shouldAppendObjectClassToReuseIdentifier)] + && [collectionViewCellClass shouldAppendObjectClassToReuseIdentifier]) { + identifier = [identifier stringByAppendingFormat:@".%@", NSStringFromClass([object class])]; + } + [collectionView registerClass:collectionViewCellClass forCellWithReuseIdentifier:identifier]; cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];