先来看下效果:

公司在做一个报修工单的功能,其中主要功能点在于,这个功能不完全是静态显示的, 它还可以点击回复,在下面增加评论,可以点击查看评论详情,也可以收回评论详情, 评论可以带图片,也可以不带图片,工单内容可以带图片,也可以不带图片。 并且回复内容的条数也不确定,就是因为这样的不确定性,一定程度增加了开发的难度。

根据MVC的思想,最初Cell应该自带一个数据模型dataModel,单现在我们多增加一个Frame模型, frame模型里面包含了各个子控件的frame值,并且自带数据模型dataModel属性,  我们就是在设置dataModel的时候 给frame计算每一个cell的高度

首先我们要准备数据模型,有了数据模型,才能计算文字的大小,才能得到Frame模型 

以下是数据模型的代码:

#import <Foundation/Foundation.h>

@interface RepairOrderModel : NSObject

@property (nonatomic,strong) NSString * repair_id;
@property (nonatomic,strong) NSString * faddress;
@property (nonatomic,strong) NSArray * comment_imag_list;
@property (nonatomic,strong) NSString * fservicecontent;
@property (nonatomic,strong) NSString * frealname;
@property (nonatomic,strong) NSString * fordernum;
@property (nonatomic,strong) NSString * power_do;
@property (nonatomic,strong) NSString * fusername;
@property (nonatomic,strong) NSString * fcreatetime;
@property (nonatomic,strong) NSString * fstatus;
@property (nonatomic,strong) NSArray * reply_list;
@property (nonatomic,strong) NSArray * repairs_imag_list;
@property (nonatomic,strong) NSString * comment_score;
@property (nonatomic,strong) NSString * normal_do;
@property (nonatomic,strong) NSString * comment_content;
@property (nonatomic,strong) NSString * fremindercount; // 加急状态

-(instancetype)initWithDict:(NSDictionary *)dict;
 (instancetype)repairModelWithDict:(NSDictionary *)dict;
@end

先来看看Frame模型的代码: 

在.h文件里:

 #import <Foundation/Foundation.h>
#import "RepairViewFrame.h" // 回复评论列表的区域frame
@class RepairOrderModel;
@interface RepairOrderFrame : NSObject
/** 是否展开回复 默认是NO*/
@property (nonatomic,assign) BOOL isOpenReply;

/**
 * 头像的frame ,结构体用assin
 */
@property (nonatomic, assign, readonly) CGRect iconF;
/**
 * 业主名的frame
 */
@property (nonatomic, assign, readonly) CGRect nameF;
/**
 * 订单时间的frame
 */
@property (nonatomic, assign, readonly) CGRect timeF;
/**
 * 订单内容的frame
 */
@property (nonatomic, assign, readonly) CGRect desF;
/**
 * 业主地址的frame
 */
@property (nonatomic, assign, readonly) CGRect addF;
/**
 * 订单号码的frame
 */
@property (nonatomic, assign, readonly) CGRect orderNumF;
/**
 * 加急状态的frame
 */
@property (nonatomic, assign, readonly) CGRect urgentF;
/**
 * 配图1的frame
 */
@property (nonatomic, assign, readonly) CGRect image1ListF;
/**
 * 配图2的frame
 */
@property (nonatomic, assign, readonly) CGRect image2ListF;
/**
 * 配图3的frame
 */
@property (nonatomic, assign, readonly) CGRect image3ListF;
/**
 * 派单按钮的frame
 */
@property (nonatomic, assign, readonly) CGRect sendOrdersBtnF;
/**
 * 派单状态的frame
 */
@property (nonatomic, assign, readonly) CGRect sendStateF;
/**
 * 接受按钮的frame
 */
@property (nonatomic, assign, readonly) CGRect acceptBtnF;
/**
 * 评论按钮的frame
 */
@property (nonatomic, assign, readonly) CGRect commandBtnF;
/**
 * 评论数量的frame
 */
@property (nonatomic, assign, readonly) CGRect countLabelF;
/**
 * 详情按钮的frame
 */
@property (nonatomic, assign, readonly) CGRect detailBtnF;
/**
 * 回复区域的frame
 */
@property (nonatomic, assign, readonly) CGRect commandViewF;
/**
 * 回复区域内部的frame模型数组 装RepairViewFrame 模型
 */
@property (nonatomic,strong) NSMutableArray * repairViewFrameArr;

//@property (nonatomic, assign, readonly) RepairViewFrame * commandFrameModel;


/**
 * cell的高度
 */
@property (nonatomic, assign, readonly) CGFloat cellHeight;

@property (nonatomic, strong) RepairOrderModel *model;  //只有拿到模型数据才能算这些属性的frame,readonly:在这个模型里面的frame属性别人不能乱改,只能访问
@end

因为我这个页面比较复杂 子控件比较多 所以属性也很多 

注意:我这里还有一个属性是repairViewFrameArr 这个是装载我回复区域的每一条回复的Frame

我把回复区域的每一条回复单独做了另外一个View,所以每一个回复View就要对应一个回复Frame

我就把所有回复的Frame装在这个数组里。(如果你们的页面没有回复区域,此处省略)

在设置Frame模型的实现文件.m里 

切记,在Frame模型中计算大小设置的字号应该和cell中展现一样

// 小号字体
#define SmallFont [UIFont systemFontOfSize:12]
// 中号字体
#define MiddleFont [UIFont systemFontOfSize:14]
// 正常字体
#define LargeFont [UIFont systemFontOfSize:16]


#import "RepairOrderFrame.h" 
#import "RepairOrderModel.h" // 数据模型
@implementation RepairOrderFrame

-(instancetype)init{
  if (self = [super init]) {
    self.isOpenReply = NO;
    self.repairViewFrameArr = [NSMutableArray array];  //回复数组(里面装载回复的Frame模型)
  }
  return self;
}

/**
 * 计算文字尺寸
 *
 * @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;
}


- (void)setModel:(RepairOrderModel *)model //重写set方法,接收模型数据为本类的属性赋值
{
  _model = model;

  // 子控件之间的间距
  CGFloat padding = 10;

  // 1.头像
  CGFloat iconX = padding;
  CGFloat iconY = padding;
  CGFloat iconW = 40;
  CGFloat iconH = 40;
  _iconF = CGRectMake(iconX, iconY, iconW, iconH);

  // 2.业主名字
  CGSize nameSize = [self sizeWithText:self.model.frealname font:LargeFont maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
  CGFloat nameX = CGRectGetMaxX(_iconF)   padding;
  CGFloat nameY = iconY   10;
  _nameF = CGRectMake(nameX, nameY, nameSize.width, nameSize.height);


  // 3.日期
  CGSize timeSize = [self sizeWithText:self.model.fcreatetime font:SmallFont maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
  CGFloat timeX = CGRectGetMaxX(_iconF)   padding;
  CGFloat timeY = nameY   nameSize.height;
  _timeF = CGRectMake(timeX, timeY, timeSize.width, timeSize.height);


  // 4.地址
  CGSize addSize = [self sizeWithText:self.model.faddress font:LargeFont maxSize:CGSizeMake(120, MAXFLOAT)];
  CGFloat addX = ScreenWidth - addSize.width - padding;
  CGFloat addY = nameY;
  _addF = CGRectMake(addX, addY, addSize.width, nameSize.height);

  // 5.单号
  CGSize orderNumSize = [self sizeWithText:[NSString stringWithFormat:@"单号:%@",self.model.fordernum] font:SmallFont maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
  CGFloat orderNumX = ScreenWidth - orderNumSize.width - padding;
  CGFloat orderNumY = timeY;
  _orderNumF = CGRectMake(orderNumX, orderNumY, orderNumSize.width, orderNumSize.height);

  // 6.加急
  CGSize urgentSize = [self sizeWithText:@"加急" font:MiddleFont maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
  CGFloat urgentX = timeX;
  CGFloat urgentY = timeY   timeSize.height   2 * padding;
  _urgentF = CGRectMake(urgentX, urgentY, urgentSize.width, urgentSize.height);

  // 7.服务内容
  CGSize desSize = [self sizeWithText:self.model.fservicecontent font:MiddleFont maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
  CGFloat desX = urgentX   urgentSize.width   2;
  CGFloat desY = timeY   timeSize.height   2 * padding;
  _desF = CGRectMake(desX, desY, desSize.width, desSize.height);

  // 8.图片列表 (最多三张)
  if (self.model.repairs_imag_list.count != 0) {// 有配图
    CGFloat width = 70;
    switch (self.model.repairs_imag_list.count) {
      case 3:
      {
        CGFloat pictureX = nameX   2 * padding   2 * width ;
        CGFloat pictureY = CGRectGetMaxY(_desF)   1.5 * padding;
        _image3ListF = CGRectMake(pictureX, pictureY, width, width);
      }

      case 2:
      {
        CGFloat pictureX = nameX   padding   width;
        CGFloat pictureY = CGRectGetMaxY(_desF)   1.5 * padding;
        _image2ListF = CGRectMake(pictureX, pictureY, width, width);
      }

      case 1:
      {
        CGFloat pictureX = nameX;
        CGFloat pictureY = CGRectGetMaxY(_desF)   1.5 * padding;
        _image1ListF = CGRectMake(pictureX, pictureY, width, width);
      }
        break;
    }


  }
  else{
    _image1ListF = CGRectMake(0, CGRectGetMaxY(_desF)   1.5 * padding , 0, 0);
    _image2ListF = CGRectMake(0, CGRectGetMaxY(_desF)   1.5 * padding , 0, 0);
    _image3ListF = CGRectMake(0, CGRectGetMaxY(_desF)   1.5 * padding , 0, 0);
  }

  // 9.派单button
  CGFloat sendOrderX = 1.5 * padding;
  CGFloat sendOrderY = CGRectGetMaxY(_image1ListF)   padding;
  CGFloat sendOrderW = 30;
  CGFloat sendOrderH = 30;
  _sendOrdersBtnF = CGRectMake(sendOrderX, sendOrderY, sendOrderW, sendOrderH);

  // 10.派单状态
  CGSize sendStateSize = [self sizeWithText:@"派单" font:MiddleFont maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
  CGFloat sendStateX = CGRectGetMaxX(_sendOrdersBtnF)   padding;
  CGFloat sendStateY = sendOrderY   padding;
  _sendStateF = CGRectMake(sendStateX, sendStateY, sendStateSize.width, sendStateSize.height);


  // 11.接受button
  CGFloat acceptX = CGRectGetMaxX(_sendStateF)  padding;
  CGFloat acceptY = sendStateY;
  CGFloat acceptW = 40;
  CGFloat acceptH = 25;
  _acceptBtnF = CGRectMake(acceptX, acceptY, acceptW, acceptH);

  // 12.评论button
  CGFloat commandX = ScreenWidth - padding - 120;
  CGFloat commandY = sendOrderY;
  CGFloat commandW = 30;
  CGFloat commandH = 30;
  _commandBtnF = CGRectMake(commandX, commandY, commandW, commandH);

  // 13.评论数量
  CGFloat countX = commandX   commandW   2;
  CGFloat countY = commandY   commandH - 15;
  CGFloat countW = 20;
  CGFloat countH = 15;
  _countLabelF = CGRectMake(countX, countY, countW, countH);

  // 14.详情button
  CGFloat detailBtnX = ScreenWidth - padding - 60;
  CGFloat detailBtnY = sendOrderY   10;
  CGFloat detailBtnW = 40;
  CGFloat detailBtnH = 25;
  _detailBtnF = CGRectMake(detailBtnX, detailBtnY, detailBtnW, detailBtnH);


  // 15.回复区域 (此处就是增加了每一条回复的Frame模型)
  CGFloat reply_listHeight = 0.0;
  if (model.reply_list.count != 0) {
    [self.repairViewFrameArr removeAllObjects];
    // 头像 同派单一样大小和高度
    for (int i = 0; i < model.reply_list.count; i   ) {
      RepairViewFrame * repairFrame = [[RepairViewFrame alloc]init];
      repairFrame.replyDic = model.reply_list[i];
      reply_listHeight  = repairFrame.viewHeight;
      [self.repairViewFrameArr addObject:repairFrame];
    }

  }

  NSLog(@"回复区域的高度 === %f",reply_listHeight);

  CGFloat commandViewX = 0;
  CGFloat commandViewY = detailBtnY   detailBtnH   padding * 2;
  CGFloat commandViewW = ScreenWidth;
  CGFloat commandViewH = reply_listHeight;
  _commandViewF = CGRectMake(commandViewX, commandViewY, commandViewW, commandViewH);

  _cellHeight = CGRectGetMaxY(_detailBtnF)   2 * padding;
  if (self.isOpenReply) {
    _cellHeight  = reply_listHeight;
  }


}

之后我们来看看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()%6, random()%6, random()%6);
    [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;
  }
}

Controller界面就是把model放入cell里 

主要代码:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  RepairOrderTableViewCell *cell = [RepairOrderTableViewCell cellWithTableview:tableView];
  cell.currentIndexPath = indexPath;
  NSLog(@"改变前cell高度: %f",cell.statusFrame.cellHeight);
  [cell pushPhotoVC:^(NSArray *imageList) {
    //图片展示
    self.lookImageList = imageList;
    [self photoTap];
  }];
  [cell pushRealVC:^(NSString *frealname) {
    //跳转业主详情页
    OwnerViewController * ownerVC = [[OwnerViewController alloc]init];
    [self.navigationController pushViewController:ownerVC animated:YES];
  }];
  [cell lookReplyDetailView:^(NSIndexPath *myIndexPath,BOOL isOpen) {
    cell.statusFrame.isOpenReply = isOpen;
    [cell.statusFrame setModel:cell.statusFrame.model];
    NSLog(@"indexPath.row == %d",myIndexPath.row);
    //刷新这一行
    [tableView reloadRowsAtIndexPaths:@[myIndexPath] withRowAnimation:UITableViewRowAnimationNone];
    //    [tableView reloadData];
  }];
  [cell pushCommandViewController:^{
    //跳转去评论页面
    OrderCommandViewController * commandVC = [[OrderCommandViewController alloc]init];
    [self.navigationController pushViewController:commandVC animated:YES];
  }];
  cell.model = ((RepairOrderFrame *)self.framesArr[indexPath.row]).model;
  cell.statusFrame = self.framesArr[indexPath.row];
  return cell;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持Devmax。

IOS开发QQ空间/朋友圈类界面的搭建的更多相关文章

  1. HTML5在微信内置浏览器下右上角菜单的调整字体导致页面显示错乱的问题

    HTML5在微信内置浏览器下,在右上角菜单的调整字体导致页面显示错乱的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

  2. iOS实现拖拽View跟随手指浮动效果

    这篇文章主要为大家详细介绍了iOS实现拖拽View跟随手指浮动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  3. ios – containerURLForSecurityApplicationGroupIdentifier:在iPhone和Watch模拟器上给出不同的结果

    我使用默认的XCode模板创建了一个WatchKit应用程序.我向iOSTarget,WatchkitAppTarget和WatchkitAppExtensionTarget添加了应用程序组权利.(这是应用程序组名称:group.com.lombax.fiveminutes)然后,我尝试使用iOSApp和WatchKitExtension访问共享文件夹URL:延期:iOS应用:但是,测试NSURL

  4. ios – Testflight无法安装应用程序

    我有几个测试人员注册了testflight并连接了他们的设备……他们有不同的ios型号……但是所有这些都有同样的问题.当他们从“safari”或“testflight”应用程序本身单击应用程序的安装按钮时……达到约90%并出现错误消息…

  5. ibm-mobilefirst – 在iOS 7.1上获取“无法安装应用程序,因为证书无效”错误

    当我的客户端将他们的设备更新到iOS7.1,然后尝试从AppCenter更新我们的应用程序时,我收到了上述错误.经过一番搜索,我找到了一个类似问题的帖子here.但是后来因为我在客户端使用AppCenter更新应用程序的环境中,我无法使用USB插件并为他们安装应用程序.在发布支持之前,是否有通过AppCenter进行下载的解决方法?

  6. ios – 视图的简单拖放?

    我正在学习iOS,但我找不到如何向UIView添加拖放行为.我试过了:它说“UIView没有可见的接口声明选择器addTarget”此外,我尝试添加平移手势识别器,但不确定这是否是我需要的它被称为,但不知道如何获得事件的坐标.在iOS中注册移动事件回调/拖放操作的标准简单方法是什么?

  7. ios – 什么控制iTunes中iPhone应用程序支持的语言列表?

    什么控制iPhone应用程序的iTunes页面中支持的语言?

  8. ios – 获得APNs响应BadDeviceToken或Unregistered的可能原因是什么?

    我知道设备令牌在某些时候是有效的.用户如何使其设备令牌变坏?从关于“未注册”的文档:Thedevicetokenisinactiveforthespecifiedtopic.这是否意味着应用程序已被删除?.您应该看到四种分发方法:如果您选择AppStore或Enterprise,您将在后面的对话框中看到Xcode将APNS权利更改为生产:如果选择AdHoc或Development,则aps-environment下的文本将是开发,然后应与后端的配置匹配.

  9. ios – 当我关闭应用程序时,我从调试器获得消息:由于信号15而终止

    我怎么能解决这个问题,我不知道这个链接MypreviousproblemaboutCoredata对我的问题有影响吗?当我cmd应用程序的Q时,将出现此消息.Messagefromdebugger:Terminatedduetosignal15如果谁知道我以前的问题的解决方案,请告诉我.解决方法>来自调试器的消息:每当用户通过CMD-Q(退出)或STOP手动终止应用程序(无论是在iOS模拟器中还是

  10. ios – NSUbiquityIdentityDidChangeNotification和SIGKILL

    当应用程序被发送到后台时,我们会删除观察者吗?我遇到的问题是,当UbiquityToken发生变化时,应用程序终止,因为用户已经更改了iCloud设置.你们如何设法订阅这个通知,如果你不这样做,你会做什么来跟踪当前登录的iCloud用户?

随机推荐

  1. iOS实现拖拽View跟随手指浮动效果

    这篇文章主要为大家详细介绍了iOS实现拖拽View跟随手指浮动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  2. iOS – genstrings:无法连接到输出目录en.lproj

    使用我桌面上的项目文件夹,我启动终端输入:cd然后将我的项目文件夹拖到终端,它给了我路径.然后我将这行代码粘贴到终端中找.-name*.m|xargsgenstrings-oen.lproj我在终端中收到此错误消息:genstrings:无法连接到输出目录en.lproj它多次打印这行,然后说我的项目是一个目录的路径?没有.strings文件.对我做错了什么的想法?

  3. iOS 7 UIButtonBarItem图像没有色调

    如何确保按钮图标采用全局色调?解决方法只是想将其转换为根注释,以便为“回答”复选标记提供更好的上下文,并提供更好的格式.我能想出这个!

  4. ios – 在自定义相机层的AVFoundation中自动对焦和自动曝光

    为AVFoundation定制图层相机创建精确的自动对焦和曝光的最佳方法是什么?

  5. ios – Xcode找不到Alamofire,错误:没有这样的模块’Alamofire’

    我正在尝试按照github(https://github.com/Alamofire/Alamofire#cocoapods)指令将Alamofire包含在我的Swift项目中.我创建了一个新项目,导航到项目目录并运行此命令sudogeminstallcocoapods.然后我面临以下错误:搜索后我设法通过运行此命令安装cocoapodssudogeminstall-n/usr/local/bin

  6. ios – 在没有iPhone6s或更新的情况下测试ARKit

    我在决定下载Xcode9之前.我想玩新的框架–ARKit.我知道要用ARKit运行app我需要一个带有A9芯片或更新版本的设备.不幸的是我有一个较旧的.我的问题是已经下载了新Xcode的人.在我的情况下有可能运行ARKit应用程序吗?那个或其他任何模拟器?任何想法或我将不得不购买新设备?解决方法任何iOS11设备都可以使用ARKit,但是具有高质量AR体验的全球跟踪功能需要使用A9或更高版本处理器的设备.使用iOS11测试版更新您的设备是必要的.

  7. 将iOS应用移植到Android

    我们制作了一个具有2000个目标c类的退出大型iOS应用程序.我想知道有一个最佳实践指南将其移植到Android?此外,由于我们的应用程序大量使用UINavigation和UIView控制器,我想知道在Android上有类似的模型和实现.谢谢到目前为止,guenter解决方法老实说,我认为你正在计划的只是制作难以维护的糟糕代码.我意识到这听起来像很多工作,但从长远来看它会更容易,我只是将应用程序的概念“移植”到android并从头开始编写.

  8. ios – 在Swift中覆盖Objective C类方法

    我是Swift的初学者,我正在尝试在Swift项目中使用JSONModel.我想从JSONModel覆盖方法keyMapper,但我没有找到如何覆盖模型类中的Objective-C类方法.该方法的签名是:我怎样才能做到这一点?解决方法您可以像覆盖实例方法一样执行此操作,但使用class关键字除外:

  9. ios – 在WKWebView中获取链接URL

    我想在WKWebView中获取tapped链接的url.链接采用自定义格式,可触发应用中的某些操作.例如HTTP://我的网站/帮助#深层链接对讲.我这样使用KVO:这在第一次点击链接时效果很好.但是,如果我连续两次点击相同的链接,它将不报告链接点击.是否有解决方法来解决这个问题,以便我可以检测每个点击并获取链接?任何关于这个的指针都会很棒!解决方法像这样更改addobserver在observeValue函数中,您可以获得两个值

  10. ios – 在Swift的UIView中找到UILabel

    我正在尝试在我的UIViewControllers的超级视图中找到我的UILabels.这是我的代码:这是在Objective-C中推荐的方式,但是在Swift中我只得到UIViews和CALayer.我肯定在提供给这个方法的视图中有UILabel.我错过了什么?我的UIViewController中的调用:解决方法使用函数式编程概念可以更轻松地实现这一目标.

返回
顶部