当前位置: 移动技术网 > 移动技术>移动开发>IOS > IOS开发QQ空间/朋友圈类界面的搭建

IOS开发QQ空间/朋友圈类界面的搭建

2019年07月24日  | 移动技术网移动技术  | 我要评论

先来看下效果:

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

根据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()%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;
  }
}

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;
}

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网