Skip to content

Commit

Permalink
[collections] Add shouldAppendObjectClassToReuseIdentifier to the fac…
Browse files Browse the repository at this point in the history
…tory.
  • Loading branch information
jverkoey committed Apr 9, 2013
1 parent 65b310e commit 3c9281c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/collections/src/NICollectionViewCellFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
5 changes: 5 additions & 0 deletions src/collections/src/NICollectionViewCellFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 3c9281c

Please sign in to comment.