Last active
December 20, 2015 10:59
Revisions
-
advantis revised this gist
Oct 15, 2013 . 3 changed files with 19 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,11 @@ // #import <Foundation/Foundation.h> #import "ADVIndexedSubscripting.h" typedef void(^ADVCellConfigurationBlock)(id cell, id object); @interface ADVArrayDataSource : NSObject <ADVIndexedSubscripting, UITableViewDataSource, UICollectionViewDataSource> @property (readonly, nonatomic) NSArray *array; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -38,6 +38,12 @@ - (void) deleteObjectAtIndexPath:(NSIndexPath *)indexPath [_array removeObjectAtIndex:indexPath.row]; } #pragma mark - ADVIndexedSubscripting - (id) objectAtIndexedSubscript:(NSUInteger)index { return self.array[index]; } #pragma mark - UITableViewDataSource - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { @@ -46,9 +52,8 @@ - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSIntege - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath]; self.configurationBlock(cell, self[indexPath.row]); return cell; } @@ -75,10 +80,9 @@ - (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInS - (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:self.cellIdentifier forIndexPath:indexPath]; self.configurationBlock(cell, self[indexPath.row]); return cell; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ // // Copyright © 2013 Yuri Kotov // #import <Foundation/Foundation.h> @protocol ADVIndexedSubscripting <NSObject> - (id) objectAtIndexedSubscript:(NSUInteger)index; @end -
advantis revised this gist
Sep 27, 2013 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -47,9 +47,9 @@ - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSIntege - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { id object = self.array[indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath]; self.configurationBlock(cell, object); return cell; } - (void) tableView:(UITableView *)tableView @@ -76,10 +76,10 @@ - (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { id object = self.array[indexPath.row]; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:self.cellIdentifier forIndexPath:indexPath]; self.configurationBlock(cell, object); return cell; } @end -
advantis revised this gist
Sep 27, 2013 . 1 changed file with 9 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -33,14 +33,6 @@ - (NSInteger) numberOfItemsInSection:(NSInteger)section return self.array.count; } - (void) deleteObjectAtIndexPath:(NSIndexPath *)indexPath { [_array removeObjectAtIndex:indexPath.row]; @@ -54,7 +46,10 @@ - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSIntege - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { id object = self.array[indexPath.row]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath]; self.configurationBlock(cell, object); return cell; } - (void) tableView:(UITableView *)tableView @@ -80,7 +75,11 @@ - (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInS - (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { id object = self.array[indexPath.row]; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:self.cellIdentifier forIndexPath:indexPath]; self.configurationBlock(cell, object); return cell; } @end -
Yuri Kotov created this gist
Jul 31, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ // // Copyright © 2013 Yuri Kotov // #import <Foundation/Foundation.h> typedef void(^ADVCellConfigurationBlock)(id cell, id object); @interface ADVArrayDataSource : NSObject <UITableViewDataSource, UICollectionViewDataSource> @property (readonly, nonatomic) NSArray *array; - (instancetype) initWithArray:(NSArray *)array reusableCellIdentifier:(NSString *)identifier cellConfigurationBlock:(ADVCellConfigurationBlock)block; @end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ // // Copyright © 2013 Yuri Kotov // #import "ADVArrayDataSource.h" @interface ADVArrayDataSource () @property (readonly, nonatomic) NSString *cellIdentifier; @property (readonly, nonatomic) ADVCellConfigurationBlock configurationBlock; @end @implementation ADVArrayDataSource { NSMutableArray *_array; } #pragma mark - ADVArrayDataSource - (instancetype) initWithArray:(NSArray *)array reusableCellIdentifier:(NSString *)identifier cellConfigurationBlock:(ADVCellConfigurationBlock)block { if ((self = [super init])) { _configurationBlock = block; _cellIdentifier = identifier; _array = [array mutableCopy]; } return self; } - (NSInteger) numberOfItemsInSection:(NSInteger)section { return self.array.count; } - (id) view:(id)view cellForItemAtIndexPath:(NSIndexPath *)indexPath { id object = self.array[indexPath.row]; UITableViewCell *cell = [view dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath]; self.configurationBlock(cell, object); return cell; } - (void) deleteObjectAtIndexPath:(NSIndexPath *)indexPath { [_array removeObjectAtIndex:indexPath.row]; } #pragma mark - UITableViewDataSource - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self numberOfItemsInSection:section]; } - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return [self view:tableView cellForItemAtIndexPath:indexPath]; } - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { switch (editingStyle) { case UITableViewCellEditingStyleDelete: [self deleteObjectAtIndexPath:indexPath]; break; default: break; } } #pragma mark - UICollectionViewDataSource - (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self numberOfItemsInSection:section]; } - (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { return [self view:collectionView cellForItemAtIndexPath:indexPath]; } @end