之后我们来看看Cell的头文件.h里:
#import <UIKit/UIKit.h>
#import "RepairOrderModel.h" // 工单数据模型头文件
#import "RepairOrderFrame.h" // 工单Frame模型头文件
typedef void (^PushPhotoBigVCBlock)(NSArray * imageList); //展示大图
typedef void (^PushRealBlock)(NSString * frealname); //跳转业主页
typedef void (^LookReplyBlock)(NSIndexPath * myIndexPath,BOOL isOpen); //点击查看回复详情
typedef void (^PushCommandVCBlock)(); //跳转评论页
@interface RepairOrderTableViewCell : UITableViewCell
@property (nonatomic,strong) RepairOrderModel* model;
-(instancetype)initWithTableview:(UITableView *)tableview;
+(instancetype)cellWithTableview:(UITableView *)tableview;
@property (nonatomic, strong) RepairOrderFrame *statusFrame;
@property (nonatomic,strong) NSIndexPath * currentIndexPath;
@property (nonatomic,copy) PushPhotoBigVCBlock block;
-(void)pushPhotoVC:(PushPhotoBigVCBlock)block;
@property (nonatomic,copy) PushRealBlock block1;
-(void)pushRealVC:(PushRealBlock)block1;
@property (nonatomic,copy) LookReplyBlock block2;
-(void)lookReplyDetailView:(LookReplyBlock)block2;
@property (nonatomic,copy) PushCommandVCBlock block3;
-(void)pushCommandViewController:(PushCommandVCBlock)block3;
@end
cell实现文件.m中:
#import "RepairOrderTableViewCell.h"
#import "ReplyDetailView.h" // 回复区域
// 小号字体
#define SmallFont [UIFont systemFontOfSize:12]
// 中号字体
#define MiddleFont [UIFont systemFontOfSize:14]
// 正常字体
#define LargeFont [UIFont systemFontOfSize:16]
@interface RepairOrderTableViewCell()
// 顶部点击区域 (增加手势)
@property (nonatomic,strong) UIView * topView;
@property (nonatomic,strong) UIImageView * iconView; //图标
@property (nonatomic,strong) UILabel * fnameLabel; //业主名
@property (nonatomic,strong) UILabel * timeLabel; //订单时间
@property (nonatomic,strong) UILabel * desLabel; //服务内容 fservicecontent
@property (nonatomic,strong) UILabel * addLabel; //订单地址 faddress
@property (nonatomic,strong) UILabel * orderNumLabel; //工单号码 fordernum
@property (nonatomic,strong) UILabel * urgentLabel; //加急状态 fremindercount
@property (nonatomic,strong) UIView * imagesListView; //图片列表 repairs_imag_list
@property (nonatomic,strong) UIButton * sendOrdersBtn; //派单按钮
@property (nonatomic,strong) UILabel * sendStateLabel; //派单状态
@property (nonatomic,strong) UIButton * acceptBtn; //接受按钮
@property (nonatomic,strong) UIButton * commandBtn; //评论按钮
@property (nonatomic,strong) UILabel * countLabel; //评论数量
@property (nonatomic,strong) UIButton * detailBtn; //详情按钮
@property (nonatomic,strong) UIImageView * photo1;
@property (nonatomic,strong) UIImageView * photo2;
@property (nonatomic,strong) UIImageView * photo3;
@end
@implementation RepairOrderTableViewCell
+(instancetype)cellWithTableview:(UITableView *)tableview{
return [[self alloc]initWithTableview:tableview];
}
-(instancetype)initWithTableview:(UITableView *)tableview{
static NSString * identify = @"RepairOrderCell";
RepairOrderTableViewCell * cell = [tableview dequeueReusableCellWithIdentifier:identify];
if (cell == nil) {
cell = [[RepairOrderTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
}
// cell的复用问题 先删除所有的回复View 不删除的话 复用cell会重影
[self deleteReplyView];
self.photo1.hidden = NO;
self.photo2.hidden = NO;
self.photo3.hidden = NO;
return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self defaultSubViews];//这里初始化各个子视图,不要给frame赋值
}
return self;
}
- (void)defaultSubViews
{
// 1.头像
self.iconView = [[UIImageView alloc] init];
[self.contentView addSubview:self.iconView];
// 2.业主名
self.fnameLabel = [[UILabel alloc] init];
self.fnameLabel.font = LargeFont;
[self.contentView addSubview:self.fnameLabel];
// 3.日期
self.timeLabel = [[UILabel alloc] init];
self.timeLabel.font = SmallFont;
[self.contentView addSubview:self.timeLabel];
// 4. 地址
self.addLabel = [[UILabel alloc] init];
self.addLabel.font = LargeFont;
[self.contentView addSubview:self.addLabel];
//5.单号
self.orderNumLabel = [[UILabel alloc] init];
self.orderNumLabel.font = SmallFont;
[self.contentView addSubview:self.orderNumLabel];
// 6.加急
self.urgentLabel = [[UILabel alloc] init];
self.urgentLabel.font = MiddleFont;
[self.contentView addSubview:self.urgentLabel];
// 7.服务内容
self.desLabel = [[UILabel alloc] init];
self.desLabel.font = MiddleFont;
[self.contentView addSubview:self.desLabel];
// 8.图片列表
self.photo1 = [[UIImageView alloc]init];
self.photo1.userInteractionEnabled = YES;
[self.contentView addSubview:self.photo1];
self.photo2 = [[UIImageView alloc]init];
self.photo2.userInteractionEnabled = YES;
[self.contentView addSubview:self.photo2];
self.photo3 = [[UIImageView alloc]init];
self.photo3.userInteractionEnabled = YES;
[self.contentView addSubview:self.photo3];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoTap)];
[self.photo1 addGestureRecognizer:tap];
UITapGestureRecognizer * tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoTap)];
[self.photo2 addGestureRecognizer:tap2];
UITapGestureRecognizer * tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(photoTap)];
[self.photo3 addGestureRecognizer:tap3];
// 9.派单按钮
self.sendOrdersBtn = [[UIButton alloc] init];
self.sendOrdersBtn.backgroundColor = mainColor;
[self.contentView addSubview:self.sendOrdersBtn];
// 10.派单状态
self.sendStateLabel = [[UILabel alloc] init];
self.sendStateLabel.font = MiddleFont;
[self.contentView addSubview:self.sendStateLabel];
// 11.接受按钮
self.acceptBtn = [[UIButton alloc] init];
self.acceptBtn.backgroundColor = mainColor;
[self.contentView addSubview:self.acceptBtn];
// 12.评论按钮
self.commandBtn = [[UIButton alloc] init];
self.commandBtn.backgroundColor = mainColor;
[self.contentView addSubview:self.commandBtn];
// 13.评论数量
self.countLabel = [[UILabel alloc] init];
self.countLabel.font = SmallFont;
[self.contentView addSubview:self.countLabel];
// 14.详情按钮
self.detailBtn = [[UIButton alloc] init];
self.detailBtn.backgroundColor = mainColor;
[self.contentView addSubview:self.detailBtn];
// 16.顶部点击事件
self.topView = [[UIView alloc]init];
[self.contentView addSubview:self.topView];
}
/**
* 在这个方法中设置子控件的frame和显示数据
*/
- (void)setStatusFrame:(RepairOrderFrame *)statusFrame
{
_statusFrame = statusFrame;
// 1.设置数据
[self settingData];
// 2.设置frame
[self settingFrame];
}
/**
* 设置数据
*/
- (void)settingData
{
// 微博数据
RepairOrderModel *dataModel = self.statusFrame.model;
// 1.头像
self.iconView.backgroundColor = mainColor;
// 2.业主名
self.fnameLabel.text = dataModel.frealname;
// 3.日期
self.timeLabel.text = dataModel.fcreatetime;
// 4. 地址
self.addLabel.text = dataModel.faddress;
//5.单号
self.orderNumLabel.text = [NSString stringWithFormat:@"单号:%@",dataModel.fordernum];
// 6.加急
self.urgentLabel.text = @"加急";
// 7.服务内容
self.desLabel.text = dataModel.fservicecontent;
// 8.图片列表
self.photo1.backgroundColor = [UIColor yellowColor];
NSArray * arr = dataModel.repairs_imag_list;
if (arr.count != 0) {
switch (arr.count) {
case 3:
{
self.photo3.hidden = NO;
[self.photo3 sd_setImageWithURL:[NSURL URLWithString:arr[2][@"fimagpath"]]];
}
case 2:
{
self.photo2.hidden = NO;
[self.photo2 sd_setImageWithURL:[NSURL URLWithString:arr[1][@"fimagpath"]]];
}
case 1:
{ self.photo1.hidden = NO;
[self.photo1 sd_setImageWithURL:[NSURL URLWithString:arr[0][@"fimagpath"]]];
}
break;
}
}
else{
self.photo1.hidden = YES;
self.photo2.hidden = YES;
self.photo3.hidden = YES;
}
// 9.派单按钮
[self.sendOrdersBtn setTitle:@"派单" forState:UIControlStateNormal];
// 10.派单状态
self.sendStateLabel.text = @"派单";
// 11.接受按钮
[self.acceptBtn setTitle:@"接受" forState:UIControlStateNormal];
// 12.评论按钮
[self.commandBtn setTitle:@"评论" forState:UIControlStateNormal];
[self.commandBtn addTarget:self action:@selector(pushCommand) forControlEvents:UIControlEventTouchUpInside];
// 13.评论数量
self.countLabel.text = [NSString stringWithFormat:@"%d",dataModel.reply_list.count];
// 14.详情按钮
[self.detailBtn setTitle:@"详情" forState:UIControlStateNormal];
[self.detailBtn addTarget:self action:@selector(replyDetail) forControlEvents:UIControlEventTouchUpInside];
if (self.statusFrame.isOpenReply) {
NSLog(@"创建评论");
[self createReplyView];
}
else{
NSLog(@"删除评论");
[self deleteReplyView];
}
}
/**
* 计算文字尺寸
*
* @param text 需要计算尺寸的文字
* @param font 文字的字体
* @param maxSize 文字的最大尺寸
*/
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
NSDictionary *attrs = @{NSFontAttributeName : font};
return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}
/**
* 设置frame
*/
- (void)settingFrame
{
// 1.头像
self.iconView.frame = self.statusFrame.iconF;
self.iconView.layer.cornerRadius = self.statusFrame.iconF.size.width/2;
// 2.业主名
self.fnameLabel.frame = self.statusFrame.nameF;
// 3.日期
self.timeLabel.frame = self.statusFrame.timeF;
// 4. 地址
self.addLabel.frame = self.statusFrame.addF;
//5.单号
self.orderNumLabel.frame = self.statusFrame.orderNumF;
// 6.加急
self.urgentLabel.frame = self.statusFrame.urgentF;
// 7.服务内容
self.desLabel.frame = self.statusFrame.desF;
// 8.图片列表
if (self.statusFrame.model.repairs_imag_list.count != 0) {
switch (self.statusFrame.model.repairs_imag_list.count) {
case 3:
{
self.photo3.frame = self.statusFrame.image3ListF;
}
case 2:
{
self.photo2.frame = self.statusFrame.image2ListF;
}
case 1:
{
self.photo1.frame = self.statusFrame.image1ListF;
}
break;
}
}
// 9.派单按钮
self.sendOrdersBtn.frame = self.statusFrame.sendOrdersBtnF;
self.sendOrdersBtn.layer.cornerRadius = self.statusFrame.sendOrdersBtnF.size.width/2;
// 10.派单状态
self.sendStateLabel.frame = self.statusFrame.sendStateF;
// 11.接受按钮
self.acceptBtn.frame = self.statusFrame.acceptBtnF;
// 12.评论按钮
self.commandBtn.frame = self.statusFrame.commandBtnF;
self.commandBtn.layer.cornerRadius = self.statusFrame.commandBtnF.size.width/2;
// 13.评论数量
self.countLabel.frame = self.statusFrame.countLabelF;
// 14.详情按钮
self.detailBtn.frame = self.statusFrame.detailBtnF;
// 16.增加顶部点击事件:
self.topView.frame = CGRectMake(0, 0, ScreenWidth, CGRectGetMaxY(self.iconView.frame));
self.topView.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer * topViewClickTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(topViewClick)];
[self.topView addGestureRecognizer:topViewClickTap];
}
#pragma mark - 创建评论区域
-(void)createReplyView{
[self deleteReplyView];
CGFloat viewY = self.statusFrame.cellHeight;
for (int i = self.statusFrame.repairViewFrameArr.count - 1; i >= 0 ; i --) {
NSLog(@"111111111111111111111111111111 %d",self.statusFrame.repairViewFrameArr.count);
RepairViewFrame * rFrame = self.statusFrame.repairViewFrameArr[i];
RepairViewFrame * rLastFrame;
viewY -= rFrame.viewHeight;
ReplyDetailView * view = [[ReplyDetailView alloc]init];
view.tag = 5000 + i;
view.frame = CGRectMake(0, viewY, ScreenWidth, rFrame.viewHeight);
view.backgroundColor = MYColor(random()%256, random()%256, random()%256);
[self.contentView addSubview:view];
}
}
#pragma mark - 删除评论区域
-(void)deleteReplyView{
for (int i = 0; i < self.statusFrame.repairViewFrameArr.count; i ++) {
ReplyDetailView * view = (ReplyDetailView *)[self.contentView viewWithTag:5000 + i];
[view removeFromSuperview];
}
}
#pragma mark - 查看大图
-(void)photoTap{
if (self.block) {
self.block(self.statusFrame.model.repairs_imag_list);
}
}
#pragma mark - 进入业主详情
-(void)topViewClick{
NSLog(@"业主详情");
if (self.block1) {
self.block1(self.statusFrame.model.frealname);
}
}
#pragma mark - 查看回复详情
-(void)replyDetail{
//先判断是否有回复
if (self.model.reply_list.count == 0) {
return;
}
self.statusFrame.isOpenReply = !self.statusFrame.isOpenReply;
if (self.statusFrame.isOpenReply) {
NSLog(@"打开评论");
// [self createReplyView];
}
else{
NSLog(@"关闭评论");
[self deleteReplyView];
}
if (self.block2) {
self.block2(self.currentIndexPath,self.statusFrame.isOpenReply);
}
}
#pragma mark - 跳转去评论页面
-(void)pushCommand{
if (self.block3) {
self.block3();
}
}
-(void)pushPhotoVC:(PushPhotoBigVCBlock)block{
if (!self.block) {
self.block = block;
}
}
-(void)pushRealVC:(PushRealBlock)block1{
if (!self.block1) {
self.block1 = block1;
}
}
-(void)lookReplyDetailView:(LookReplyBlock)block2{
if (!self.block2) {
self.block2 = block2;
}
}
-(void)pushCommandViewController:(PushCommandVCBlock)block3{
if (!self.block3) {
self.block3 = block3;
}
}










