服务器之家

服务器之家 > 正文

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

时间:2021-02-22 14:05     来源/作者:NULLGIRL

先来看下效果:
IOS开发QQ空间/朋友圈类界面的搭建

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

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

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

以下是数据模型的代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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文件里:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#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中展现一样

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// 小号字体
#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里:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#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中:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#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里 

主要代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
- (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;
}

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

原文链接:http://blog.csdn.net/boring_cat/article/details/51758796

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部