-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utilities for dequeueing views from a collection view.
- Loading branch information
Showing
12 changed files
with
295 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright Maarten Billemont (http://www.lhunath.com, lhunath@lyndir.com) | ||
* | ||
* See the enclosed file LICENSE for license information (LGPLv3). If you did | ||
* not receive this file, see http://www.gnu.org/licenses/lgpl-3.0.txt | ||
* | ||
* @author Maarten Billemont <lhunath@lyndir.com> | ||
* @license http://www.gnu.org/licenses/lgpl-3.0.txt | ||
*/ | ||
|
||
// | ||
// UICollectionReusableView(PearlDequeue) | ||
// | ||
// Created by Maarten Billemont on 2014-05-26. | ||
// Copyright 2014 lhunath (Maarten Billemont). All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
|
||
@interface UICollectionReusableView(PearlDequeue) | ||
|
||
+ (instancetype)templateCellFromCollectionView:(UICollectionView *)collectionView; | ||
+ (instancetype)templateSupplementaryFromCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind; | ||
|
||
+ (instancetype)dequeueCellFromCollectionView:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath; | ||
+ (instancetype)dequeueSupplementaryFromCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind | ||
indexPath:(NSIndexPath *)indexPath; | ||
|
||
+ (void)registerCellWithCollectionView:(UICollectionView *)collectionView; | ||
+ (void)registerCellWithCollectionView:(UICollectionView *)collectionView usingNib:(UINib *)nib; | ||
|
||
+ (void)registerSupplementaryWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind; | ||
+ (void)registerSupplementaryWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind usingNib:(UINib *)nib; | ||
|
||
+ (void)registerDecorationWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind; | ||
+ (void)registerDecorationWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind usingNib:(UINib *)nib; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* Copyright Maarten Billemont (http://www.lhunath.com, lhunath@lyndir.com) | ||
* | ||
* See the enclosed file LICENSE for license information (LGPLv3). If you did | ||
* not receive this file, see http://www.gnu.org/licenses/lgpl-3.0.txt | ||
* | ||
* @author Maarten Billemont <lhunath@lyndir.com> | ||
* @license http://www.gnu.org/licenses/lgpl-3.0.txt | ||
*/ | ||
|
||
// | ||
// UICollectionReusableView(PearlDequeue) | ||
// | ||
// Created by Maarten Billemont on 2014-05-26. | ||
// Copyright 2014 lhunath (Maarten Billemont). All rights reserved. | ||
// | ||
|
||
#import "UICollectionReusableView+PearlDequeue.h" | ||
|
||
@interface PearlTemplateCollectionViewDataSource : NSObject <UICollectionViewDataSource> | ||
|
||
@property(nonatomic) NSString *identifier; | ||
|
||
+ (instancetype)templateSourceForIdentifier:(NSString *)identifier; | ||
|
||
@end | ||
|
||
@implementation UICollectionReusableView(PearlDequeue) | ||
|
||
+ (instancetype)templateCellFromCollectionView:(UICollectionView *)collectionView { | ||
|
||
id<UICollectionViewDelegate> originalDelegate = collectionView.delegate; | ||
id<UICollectionViewDataSource> originalDataSource = collectionView.dataSource; | ||
collectionView.delegate = nil; | ||
collectionView.dataSource = [PearlTemplateCollectionViewDataSource templateSourceForIdentifier:NSStringFromClass( self )]; | ||
id template = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass( self ) | ||
forIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; | ||
collectionView.delegate = originalDelegate; | ||
collectionView.dataSource = originalDataSource; | ||
[collectionView reloadData]; | ||
|
||
return template; | ||
} | ||
|
||
+ (instancetype)templateSupplementaryFromCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind { | ||
|
||
id<UICollectionViewDataSource> originalDataSource = collectionView.dataSource; | ||
collectionView.dataSource = [PearlTemplateCollectionViewDataSource templateSourceForIdentifier:NSStringFromClass( self )]; | ||
id template = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:NSStringFromClass( self ) | ||
forIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; | ||
collectionView.dataSource = originalDataSource; | ||
[collectionView reloadData]; | ||
|
||
return template; | ||
} | ||
|
||
+ (instancetype)dequeueCellFromCollectionView:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath { | ||
|
||
return [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass( self ) forIndexPath:indexPath]; | ||
} | ||
|
||
+ (instancetype)dequeueSupplementaryFromCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind | ||
indexPath:(NSIndexPath *)indexPath { | ||
|
||
return [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:NSStringFromClass( self ) forIndexPath:indexPath]; | ||
} | ||
|
||
+ (void)registerCellWithCollectionView:(UICollectionView *)collectionView { | ||
|
||
[collectionView registerClass:self forCellWithReuseIdentifier:NSStringFromClass( self )]; | ||
} | ||
|
||
+ (void)registerCellWithCollectionView:(UICollectionView *)collectionView usingNib:(UINib *)nib { | ||
|
||
[collectionView registerNib:nib forCellWithReuseIdentifier:NSStringFromClass( self )]; | ||
} | ||
|
||
+ (void)registerSupplementaryWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind { | ||
|
||
[collectionView registerClass:self forSupplementaryViewOfKind:kind withReuseIdentifier:NSStringFromClass( self )]; | ||
} | ||
|
||
+ (void)registerSupplementaryWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind usingNib:(UINib *)nib { | ||
|
||
[collectionView registerNib:nib forSupplementaryViewOfKind:kind withReuseIdentifier:NSStringFromClass( self )]; | ||
} | ||
|
||
+ (void)registerDecorationWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind { | ||
|
||
[collectionView.collectionViewLayout registerClass:self forDecorationViewOfKind:kind]; | ||
} | ||
|
||
+ (void)registerDecorationWithCollectionView:(UICollectionView *)collectionView kind:(NSString *)kind usingNib:(UINib *)nib { | ||
|
||
[collectionView.collectionViewLayout registerNib:nib forDecorationViewOfKind:kind]; | ||
} | ||
|
||
@end | ||
|
||
@implementation PearlTemplateCollectionViewDataSource | ||
|
||
+ (instancetype)templateSourceForIdentifier:(NSString *)identifier { | ||
|
||
PearlTemplateCollectionViewDataSource *dataSource = [self new]; | ||
dataSource.identifier = identifier; | ||
|
||
return dataSource; | ||
} | ||
|
||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { | ||
|
||
return 1; | ||
} | ||
|
||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { | ||
|
||
return 1; | ||
} | ||
|
||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { | ||
|
||
return [collectionView dequeueReusableCellWithReuseIdentifier:self.identifier forIndexPath:indexPath]; | ||
} | ||
|
||
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind | ||
atIndexPath:(NSIndexPath *)indexPath { | ||
|
||
return [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:self.identifier forIndexPath:indexPath]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright Maarten Billemont (http://www.lhunath.com, lhunath@lyndir.com) | ||
* | ||
* See the enclosed file LICENSE for license information (LGPLv3). If you did | ||
* not receive this file, see http://www.gnu.org/licenses/lgpl-3.0.txt | ||
* | ||
* @author Maarten Billemont <lhunath@lyndir.com> | ||
* @license http://www.gnu.org/licenses/lgpl-3.0.txt | ||
*/ | ||
|
||
// | ||
// UITableView(PearlReloadFromArray) | ||
// | ||
// Created by Maarten Billemont on 2014-05-21. | ||
// Copyright 2014 lhunath (Maarten Billemont). All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface UITableView(PearlReloadFromArray) | ||
|
||
- (void)reloadRowsFromArray:(NSArray *)fromArray toArray:(NSArray *)toArray inSection:(NSInteger)section; | ||
- (void)reloadRowsFromArray:(NSArray *)fromArray toArray:(NSArray *)toArray inSection:(NSInteger)section | ||
withRowAnimation:(UITableViewRowAnimation)animation; | ||
|
||
@end |
20 changes: 16 additions & 4 deletions
20
Pearl-UIKit/UITableView+ReloadFromArray.m → ...-UIKit/UITableView+PearlReloadFromArray.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.