Skip to content

Commit

Permalink
indexPath && cell
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWicky committed Jan 14, 2020
1 parent 3be1001 commit 4994038
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 16 additions & 0 deletions DWTableViewHelper/DWTableViewHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,22 @@ typedef NS_ENUM(NSUInteger, DWTableViewHelperLoadDataMode) {///数据加载优
///配合DWTableViewHelperLoadDataIgnoreHighSpeedMode使用,标志cell是否被绘制过
@property (nonatomic ,assign ,readonly) BOOL cellHasBeenDrawn;

/**
当前正在展示的cell
在willDisplayCell之后被赋值为对应的cell,在didEndDisplaying之后被置空
*/
@property (nonatomic ,weak ,readonly) __kindof DWTableViewHelperCell * currentDisplayCell;

/**
当前正在展示的cell对应的indexPath
在willDisplayCell之后被赋值为对应的cell的indexPath,在didEndDisplaying之后被置空
*/
@property (nonatomic ,strong ,readonly) NSIndexPath * currentDisplayIndexPath;



///设置需要重新自动计算高度
-(void)setNeedsReAutoCalculateRowHeight;

Expand Down
13 changes: 11 additions & 2 deletions DWTableViewHelper/DWTableViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ @interface DWTableViewHelperModel ()

@property (nonatomic ,strong) UIImage * cellSnap;

@property (nonatomic ,weak) __kindof DWTableViewHelperCell * currentDisplayCell;

@property (nonatomic ,strong) NSIndexPath * currentDisplayIndexPath;

@end

@implementation DWTableViewHelper
Expand Down Expand Up @@ -375,6 +379,9 @@ -(void)tableView:(UITableView *)tableView willDisplayCell:(DWTableViewHelperCell
return;
}

cell.model.currentDisplayCell = cell;
cell.model.currentDisplayIndexPath = indexPath;

if (self.cellEditSelectedIcon && cell.model.cellEditSelectedIcon == ImageNull) {
cell.model.cellEditSelectedIcon = self.cellEditSelectedIcon;
}
Expand Down Expand Up @@ -409,10 +416,12 @@ - (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view
}
}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath {
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(DWTableViewHelperCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath {
if (DWDelegate && [DWDelegate respondsToSelector:@selector(dw_tableView:didEndDisplayingCell:forRowAtIndexPath:)]) {
[DWDelegate dw_tableView:tableView didEndDisplayingCell:cell forRowAtIndexPath:indexPath];
}
cell.model.currentDisplayCell = nil;
cell.model.currentDisplayIndexPath = nil;
}

- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section {
Expand Down Expand Up @@ -826,10 +835,10 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
return placeHolderCell();
}
DWTableViewHelperCell * cell = nil;
DWTableViewHelperModel * model = [self modelFromIndexPath:indexPath];
if (DWDelegate && [DWDelegate respondsToSelector:@selector(dw_tableView:cellForRowAtIndexPath:)]) {
cell = [DWDelegate dw_tableView:tableView cellForRowAtIndexPath:indexPath];
}
DWTableViewHelperModel * model = [self modelFromIndexPath:indexPath];

if (!cell) {
cell = [self createCellFromModel:model useReuse:YES];
Expand Down

0 comments on commit 4994038

Please sign in to comment.