Merge pull request #901 from Adlai-Holler/ModernizeCellLoading

ASTableView: Use Fancy dequeueReusableCellWithIdentifier:forIndexPath: Method
This commit is contained in:
appleguy 2015-12-01 17:54:45 -08:00
commit e42bcf47be
2 changed files with 9 additions and 11 deletions

View File

@ -22,6 +22,7 @@
static const NSUInteger kASCollectionViewAnimationNone = UITableViewRowAnimationNone; static const NSUInteger kASCollectionViewAnimationNone = UITableViewRowAnimationNone;
static const ASSizeRange kInvalidSizeRange = {CGSizeZero, CGSizeZero}; static const ASSizeRange kInvalidSizeRange = {CGSizeZero, CGSizeZero};
static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
#pragma mark - #pragma mark -
#pragma mark Proxying. #pragma mark Proxying.
@ -245,7 +246,7 @@ static BOOL _isInterceptedSelector(SEL sel)
self.backgroundColor = [UIColor whiteColor]; self.backgroundColor = [UIColor whiteColor];
[self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:@"_ASCollectionViewCell"]; [self registerClass:[_ASCollectionViewCell class] forCellWithReuseIdentifier:kCellReuseIdentifier];
return self; return self;
} }
@ -483,9 +484,7 @@ static BOOL _isInterceptedSelector(SEL sel)
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{ {
static NSString *reuseIdentifier = @"_ASCollectionViewCell"; _ASCollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:kCellReuseIdentifier forIndexPath:indexPath];
_ASCollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
ASCellNode *node = [_dataController nodeAtIndexPath:indexPath]; ASCellNode *node = [_dataController nodeAtIndexPath:indexPath];
cell.node = node; cell.node = node;

View File

@ -21,6 +21,8 @@
// FIXME: Temporary nonsense import until method names are finalized and exposed // FIXME: Temporary nonsense import until method names are finalized and exposed
#import "ASDisplayNode+Subclasses.h" #import "ASDisplayNode+Subclasses.h"
static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
//#define LOG(...) NSLog(__VA_ARGS__) //#define LOG(...) NSLog(__VA_ARGS__)
#define LOG(...) #define LOG(...)
@ -223,6 +225,8 @@ static BOOL _isInterceptedSelector(SEL sel)
// If the initial size is 0, expect a size change very soon which is part of the initial configuration // If the initial size is 0, expect a size change very soon which is part of the initial configuration
// and should not trigger a relayout. // and should not trigger a relayout.
_ignoreNodesConstrainedWidthChange = (_nodesConstrainedWidth == 0); _ignoreNodesConstrainedWidthChange = (_nodesConstrainedWidth == 0);
[self registerClass:_ASTableViewCell.class forCellReuseIdentifier:kCellReuseIdentifier];
} }
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
@ -528,13 +532,8 @@ static BOOL _isInterceptedSelector(SEL sel)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
static NSString *reuseIdentifier = @"_ASTableViewCell"; _ASTableViewCell *cell = [self dequeueReusableCellWithIdentifier:kCellReuseIdentifier forIndexPath:indexPath];
cell.delegate = self;
_ASTableViewCell *cell = [self dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[_ASTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
cell.delegate = self;
}
ASCellNode *node = [_dataController nodeAtIndexPath:indexPath]; ASCellNode *node = [_dataController nodeAtIndexPath:indexPath];
[_rangeController configureContentView:cell.contentView forCellNode:node]; [_rangeController configureContentView:cell.contentView forCellNode:node];