首先先来理一下具体步骤:
1、新建一个自定义的tableviewcell类
2、初始化tableviewcell时同时初始化所有子控件<这里可以先设置子控件的一些属性包括字体、颜色等>
3、提供两个模型类
a、一个是我们常用的数据模型
b、一个是frame模型(数据模型+所有子控件的frame+cell的高度)起个名modelFrame
4、在自定义的cell 中应该提供一个frame属性<modelFrame>
a、将modelFrame模型传递给cell
b、cell根据modelFrame模型给子控件设置frame,根据数据模型给子控件设置具体的数据
5、在tableview的数据源方法中返回cell 的高度
上代码
1、新建一个自定义的tableviewcell类
#import <UIKit/UIKit.h>
@class DescriptionModelFrame;
@interface DetailCell : UITableViewCell
@property(nonatomic,strong)DescriptionModelFrame * DesFrame;
@end
实现文件中
#import "DetailCell.h"
#import "DescriptionModel.h"
#import "DescriptionModelFrame.h"
@interface DetailCell()
@property(nonatomic,strong)UILabel * titleLabel;标题
@property(nonatomic,strong)UILabel * desLabel;详细描述
@end
@implementation DetailCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;//去掉cell 点击效果
[self initSubControl];
}
return self;
}
-(void)initSubControl
{
UILabel * titleLable = [[