From 489d3d421d1438b11465a744afc81b5f4fa23992 Mon Sep 17 00:00:00 2001 From: "xiaoyou.qu" Date: Sun, 26 Jun 2022 16:38:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96/=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89cell=E6=94=B9=E4=B8=BA=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E7=B1=BB=E5=9E=8B=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XYInfomationSection/XYInfomationCell.h | 3 ++- .../XYInfomationSection/XYInfomationCell.m | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/SectionDemo/XYInfomationSection/XYInfomationCell.h b/SectionDemo/XYInfomationSection/XYInfomationCell.h index 5fe9bab..49713bb 100644 --- a/SectionDemo/XYInfomationSection/XYInfomationCell.h +++ b/SectionDemo/XYInfomationSection/XYInfomationCell.h @@ -65,6 +65,7 @@ typedef NS_ENUM(NSUInteger, XYInfoCellType) { @interface XYInfomationItem : NSObject /** 图片名 default is nil + @note 若使用此属性,应使用本地图片。若传入网络图地址,会从网络下载,比较耗时 */ @property(nonatomic , copy) NSString *imageName; /** @@ -160,7 +161,7 @@ typedef NS_ENUM(NSUInteger, XYInfoCellType) { @property (nonatomic, strong) UIFont *placeholderFont; /// custom cell class - 当type == other 时候有效 -@property (nonatomic, strong) NSString *customCellClass; +@property (nonatomic, strong) Class customCellClass; /// cell 的指定 backgroundColor, default is clearColor @property (nonatomic, strong) UIColor *backgroundColor; diff --git a/SectionDemo/XYInfomationSection/XYInfomationCell.m b/SectionDemo/XYInfomationSection/XYInfomationCell.m index 918e3a3..e4202f0 100644 --- a/SectionDemo/XYInfomationSection/XYInfomationCell.m +++ b/SectionDemo/XYInfomationSection/XYInfomationCell.m @@ -347,12 +347,21 @@ + (instancetype)cellWithModel:(XYInfomationItem *)model break; case XYInfoCellTypeOther: // 如果是自定义类型,那就根据model中自定义类来创建 { - if (NSClassFromString(model.customCellClass)) { - cell = [NSClassFromString(model.customCellClass) new]; - }else - { + if ([model.customCellClass isKindOfClass:[NSNull class]]) { @throw [[NSException alloc] initWithName:@"入参错误" reason:@"model.type为Other,必须传入 customCellClass" userInfo:nil]; } + + // 兼容旧版本,v1.3之前定义 String 类型 + if ([model.customCellClass isKindOfClass:[NSString class]]) { + NSString *className = (NSString *)model.customCellClass; + if (NSClassFromString(className)) { + cell = [NSClassFromString(className) new]; + } + } else { + // 新版改为 Class 直接注册,提升性能 + cell = [model.customCellClass new]; + } + cell->_cell_type = XYInfoCellTypeOther; cell.model = model; }