Skip to content

Commit

Permalink
cell选择样式逻辑修改,默认选择样式无,选择模式下为默认模式(选择背景已去掉)。修复cellForRow中实现cellForRow代理后…
Browse files Browse the repository at this point in the history
…model为nil的bug。提升选择模式下默认代理样式优先级
CodeWicky committed May 25, 2017
1 parent d15738d commit 6dde12b
Showing 7 changed files with 52 additions and 12 deletions.
15 changes: 15 additions & 0 deletions DEMO/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PODS:
- DWAnimation (1.1.10)
- Masonry (1.0.2)

DEPENDENCIES:
- DWAnimation (~> 1.1.10)
- Masonry (~> 1.0.2)

SPEC CHECKSUMS:
DWAnimation: 2f0a7456ec9fff2da2e4d1352552b6cd593d00a9
Masonry: 7c429b56da9d4ee0bbb3ed77a5ea710d6a5df39e

PODFILE CHECKSUM: 30497533825386c1222b0a097d1e87a99eab6b69

COCOAPODS: 1.2.1
4 changes: 0 additions & 4 deletions DEMO/a.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
9B9DAC7B1EBEE62D00196BC7 /* BCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9DAC7A1EBEE62D00196BC7 /* BCell.m */; };
9B9DAC7F1EBEEE6B00196BC7 /* CCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9DAC7D1EBEEE6A00196BC7 /* CCell.m */; };
9B9DAC801EBEEE6B00196BC7 /* CCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9B9DAC7E1EBEEE6A00196BC7 /* CCell.xib */; };
9BFEB7C61EC711DF00EDE288 /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 9BFEB7C51EC711DF00EDE288 /* icon.png */; };
9BFEB7D81EC72FC600EDE288 /* DWTableViewHelperResource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 9BFEB7D71EC72FC600EDE288 /* DWTableViewHelperResource.bundle */; };
/* End PBXBuildFile section */

@@ -51,7 +50,6 @@
9B9DAC7C1EBEEE6A00196BC7 /* CCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCell.h; sourceTree = "<group>"; };
9B9DAC7D1EBEEE6A00196BC7 /* CCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCell.m; sourceTree = "<group>"; };
9B9DAC7E1EBEEE6A00196BC7 /* CCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CCell.xib; sourceTree = "<group>"; };
9BFEB7C51EC711DF00EDE288 /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon.png; path = ../../../../../icon.png; sourceTree = "<group>"; };
9BFEB7D71EC72FC600EDE288 /* DWTableViewHelperResource.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = DWTableViewHelperResource.bundle; sourceTree = "<group>"; };
B205B3A7DA99B939C9B6EA02 /* Pods-a.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-a.debug.xcconfig"; path = "Pods/Target Support Files/Pods-a/Pods-a.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -113,7 +111,6 @@
9B9DAC7C1EBEEE6A00196BC7 /* CCell.h */,
9B9DAC7D1EBEEE6A00196BC7 /* CCell.m */,
9B9DAC7E1EBEEE6A00196BC7 /* CCell.xib */,
9BFEB7C51EC711DF00EDE288 /* icon.png */,
9B4926C31EBD77C700EF58DE /* AppDelegate.h */,
9B4926C41EBD77C700EF58DE /* AppDelegate.m */,
9B4926C61EBD77C700EF58DE /* ViewController.h */,
@@ -205,7 +202,6 @@
buildActionMask = 2147483647;
files = (
9B4926D01EBD77C700EF58DE /* LaunchScreen.storyboard in Resources */,
9BFEB7C61EC711DF00EDE288 /* icon.png in Resources */,
9B9DAC801EBEEE6B00196BC7 /* CCell.xib in Resources */,
9B4926CD1EBD77C700EF58DE /* Assets.xcassets in Resources */,
9B4926CB1EBD77C700EF58DE /* Main.storyboard in Resources */,
10 changes: 10 additions & 0 deletions DEMO/a.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "0"
version = "2.0">
</Bucket>
6 changes: 5 additions & 1 deletion DEMO/a/ViewController.m
Original file line number Diff line number Diff line change
@@ -59,6 +59,10 @@ -(id)dw_TableView:(UITableView *)tableView showAnimationWithCell:(UITableViewCel
}];
}

//-(UITableViewCellEditingStyle)dw_TableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
// return UITableViewCellEditingStyleInsert;
//}

-(UITableView *)tabV {
if (!_tabV) {
_tabV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 414, 500) style:(UITableViewStyleGrouped)
@@ -68,7 +72,7 @@ -(UITableView *)tabV {
[self.helper setTheSeperatorToZero];
self.helper.minAutoRowHeight = 55;
self.helper.helperDelegate = self;
self.helper.loadDataMode = DWTableViewHelperLoadDataLazyMode;
self.helper.loadDataMode = DWTableViewHelperLoadDataIgnoreHighSpeedMode;
self.helper.ignoreCount = 1;
}
return _tabV;
1 change: 1 addition & 0 deletions DWTableViewHelper/DWTableViewHelper.h
Original file line number Diff line number Diff line change
@@ -170,6 +170,7 @@

///cell占位图(仅优化模式下有效)
-(UIImage *)dw_TableView:(UITableView *)tableView loadDataPlaceHolderForCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

@end

#pragma mark --- cell 基础属性协议---
23 changes: 16 additions & 7 deletions DWTableViewHelper/DWTableViewHelper.m
Original file line number Diff line number Diff line change
@@ -395,7 +395,7 @@ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *
{
if (self.selectEnable) {
if (!self.multiSelect && self.lastSelected) {
[tableView deselectRowAtIndexPath:self.lastSelected animated:YES];
[tableView deselectRowAtIndexPath:self.lastSelected animated:NO];
}
self.lastSelected = indexPath;
return;
@@ -414,12 +414,12 @@ -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath

///editing
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
if (DWRespond) {
return [DWDelegate dw_TableView:tableView editingStyleForRowAtIndexPath:indexPath];
}
if (self.selectEnable) {
return UITableViewCellEditingStyleInsert | UITableViewCellEditingStyleDelete;
}
if (DWRespond) {
return [DWDelegate dw_TableView:tableView editingStyleForRowAtIndexPath:indexPath];
}
return UITableViewCellEditingStyleNone;
}

@@ -551,14 +551,13 @@ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
DWTableViewHelperCell * cell = nil;
DWTableViewHelperModel * model = nil;
DWTableViewHelperModel * model = [self modelFromIndexPath:indexPath];
if (DWRespond) {
cell = [DWDelegate dw_TableView:tableView cellForRowAtIndexPath:indexPath];
if (!cell) {
NSAssert(NO, @"you have implemetation the dw_TableView:cellForRowAtIndexPath delegate but pass a nil cell at indexPath of S%ldR%ld",indexPath.section,indexPath.row);
}
} else {
model = [self modelFromIndexPath:indexPath];
cell = [self createCellFromModel:model useReuse:YES];
}
if (self.loadDataMode == DWTableViewHelperLoadDataIgnoreHighSpeedMode) {
@@ -1251,6 +1250,9 @@ @interface DWTableViewHelperModel ()
///计算的横屏行高
@property (nonatomic ,assign) CGFloat calRowHeightH;

///原始cell选择样式
@property (nonatomic ,assign) NSInteger originalSelectionStyle;

@end

@implementation DWTableViewHelperModel
@@ -1264,6 +1266,7 @@ -(instancetype)init{
if (!ImageNull) {
ImageNull = [UIImage new];
}
self.originalSelectionStyle = -1;
NSString * cellClass = NSStringFromClass([self class]);
NSArray * arr = [cellClass componentsSeparatedByString:@"Model"];
if (arr.count) {
@@ -1369,8 +1372,10 @@ -(void)layoutSubviews
///适配第一次图片为空的情况
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (self.selectionStyle == UITableViewCellSelectionStyleNone) {
if (editing && self.selectionStyle != UITableViewCellSelectionStyleDefault) {//编辑状态下保证非无选择样式
self.selectionStyle = UITableViewCellSelectionStyleDefault;
} else if (!editing && self.selectionStyle != self.model.originalSelectionStyle) {//退出编辑状态是恢复原始选择样式
self.selectionStyle = self.model.originalSelectionStyle;
}
BOOL toSetUnselectIcon = self.model.cellEditUnselectedIcon != ImageNull && self.model.cellEditUnselectedIcon != nil;
for (UIControl *control in self.subviews){
@@ -1400,6 +1405,7 @@ -(void)setupUI {
self.backgroundColor = [UIColor whiteColor];
self.multipleSelectionBackgroundView = [UIView new];
self.selectedBackgroundView = [UIView new];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.loadDataImageView = [UIImageView new];
self.loadDataImageView.backgroundColor = [UIColor whiteColor];
}
@@ -1411,6 +1417,9 @@ -(void)setupConstraints {
-(void)setModel:(__kindof DWTableViewHelperModel *)model
{
_model = model;
if (model.originalSelectionStyle == -1) {//仅在初次生成cell的时候同步cell的选择样式
model.originalSelectionStyle = self.selectionStyle;
}
}

-(void)showLoadDataPlaceHolder:(UIImage *)image height:(CGFloat)height{

0 comments on commit 6dde12b

Please sign in to comment.