admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
//
//  discoverGoodsDetailViewController.m
//  BuWanVideo2.0
//
//  Created by apple on 17/1/4.
//  Copyright © 2017年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "discoverGoodsDetailViewController.h"
 
#import "findTitleTableViewCell.h"
#import "findcommentTableViewCell.h"
#import "XYRChildTableViewCell.h"
 
#import "allCommentsViewController.h"
#import "WEBViewController.h"
#import "LoggingViewController.h"
 
//#import <AlibcTradeSDK/AlibcTradeSDK.h>
//#import <AlibcTradeSDK/AlibcTradeService.h>
//#import <AlibcTradeSDK/AlibcTradePageFactory.h>
//#import <AlibcTradeSDK/AlibcTradeShowParams.h>
 
@interface discoverGoodsDetailViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIGestureRecognizerDelegate>{
    UITableView *_tableView;
    
    UIView *_replyMessageView;  //回复的输入视图
    UIButton *sendButton;       //回复的按钮
    UITextField *_textField;    //回复的输入框
    
    UITapGestureRecognizer *Tap;//当评论框出现的时候,要把这个手势添加到tableView,当评论框消失的时候,要移除手势,否者会出现“猜你喜欢”无法点击的情况,因为手势会拦截点击事件
    BOOL _isCollection;
}
 
@property (nonatomic,strong) NSDictionary *ItemDetailMessage;       //商品详情页信息
@property (nonatomic,strong) NSArray *commentMessage;               //商品详情页评论
@property (nonatomic,strong) NSMutableArray *RecommendListData;     //猜你喜欢
 
@end
 
@implementation discoverGoodsDetailViewController
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
 
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    //增加通知中心监听,当键盘出现或消失时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    [self creatUI];
}
 
-(void)creatUI{
    if (!_tableView) {
        _tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, -22, KScreenW, KScreenH+22) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = kGlobalBackgroundColor;
        _tableView.showsVerticalScrollIndicator = NO;
        
        //注册cell
        [_tableView registerNib:[UINib nibWithNibName:@"findTitleTableViewCell" bundle:nil] forCellReuseIdentifier:@"findTitleTableViewCellID"];
        [_tableView registerNib:[UINib nibWithNibName:@"findcommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"findcommentTableViewCellID"];
        [_tableView registerNib:[UINib nibWithNibName:@"XYRChildTableViewCell" bundle:nil] forCellReuseIdentifier:@"XYRChildTableViewCellID"];
        [self.view addSubview:_tableView];
    }
    
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenW)];
    imageView.contentMode=UIViewContentModeScaleAspectFill;
    imageView.userInteractionEnabled=YES;
    
    [imageView setYthImageWithURL:_goodspic_url placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    _tableView.tableHeaderView=imageView;
    
    UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 64)];
    CAGradientLayer *gradientLayer= [CAGradientLayer layer];  //设置渐变效果
    gradientLayer.bounds = headerView.bounds;
    gradientLayer.borderWidth = 0;
    gradientLayer.frame =CGRectMake(headerView.bounds.origin.x, headerView.bounds.origin.y, KScreenW, 64);
    gradientLayer.colors = [NSArray arrayWithObjects:
                            (id)[kGlobalMainColor CGColor],
                            (id)[[UIColor clearColor] CGColor], nil];
    gradientLayer.startPoint = CGPointMake(0.0, 0.0);
    gradientLayer.endPoint = CGPointMake(0.0, 1.0);
    [headerView.layer insertSublayer:gradientLayer atIndex:0];
    [self.view addSubview:headerView];
    
    //返回按钮
    UIButton *backButton=[[UIButton alloc] initWithFrame:CGRectMake(2, 25, 70, 30)];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [backButton setTitle:@"<返回" forState:UIControlStateNormal];
//    [backButton.titleLabel setFont:[UIFont systemFontOfSize:18]];
    [backButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:backButton];
    
    //加载详细数据
    [self loadDetailData:@"疯狂加载中"];
    
    //输入框视图
    [self CommentBox];
}
 
-(void)loadDetailData:(NSString *)str{
    [SVProgressHUD showWithStatus:str];
    [[YTHNetInterface startInterface] getGoodsItemDetailWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            [SVProgressHUD dismiss];
            NSDictionary *dataGoodsDetailList=[result objectForKey:@"Data"];
            _ItemDetailMessage=[dataGoodsDetailList objectForKey:@"Item"];
            _commentMessage=[[dataGoodsDetailList objectForKey:@"comment"] objectForKey:@"data"];
            _isCollection=[[dataGoodsDetailList objectForKey:@"collect"] boolValue];
            _RecommendListData=[_ItemDetailMessage objectForKey:@"RecommendList"];
            [_tableView reloadData];
        }else{
            NSLog(@"%@",error);
            [SVProgressHUD showErrorWithStatus:@"加载失败"];
        }
    }];
}
 
-(void)CommentBox{
    //创建手势事件
    Tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignResponder)];
    Tap.delegate=self;
    
    UIImageView *backimage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, KScreenW-80 , 30)];
    backimage.image=[[UIImage imageNamed:@"输入框"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 40, 20, backimage.frame.size.width-40)];
    
    //回复的输入视图
    _replyMessageView=[[UIView alloc] initWithFrame:CGRectMake(0, _tableView.frame.size.height-50, KScreenW, 50)];
    _replyMessageView.backgroundColor=[UIColor whiteColor];
    
    //回复的输入框
    _textField=[[UITextField alloc] initWithFrame:CGRectMake(20, 10, KScreenW-90, 30)];
    _textField.delegate=self;
    _textField.backgroundColor=kGlobalBackgroundColor;
    _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _textField.placeholder=@"  我也来说两句...";
    
    //回复发送按钮
    sendButton=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW-60, 10, 50, 30)];
    [sendButton setBackgroundImage:[[UIImage imageNamed:@"发表"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
    
    [sendButton setTitleColor:kGlobalMainColor forState:UIControlStateNormal];
    [sendButton setTitle:@"发送" forState:UIControlStateNormal];
    [sendButton addTarget:self action:@selector(PostComment) forControlEvents:UIControlEventTouchUpInside];
    
    [_replyMessageView addSubview:backimage];
    [_replyMessageView addSubview:_textField];
    [_replyMessageView addSubview:sendButton];
    
    [self.view addSubview:_replyMessageView];
    [_replyMessageView setHidden:YES];
}
 
-(void)resignResponder{
    [self HideBox];
}
 
-(void)PostComment{
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
        [self HideBox];
        //已登录
        [[YTHNetInterface startInterface] addCommentWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withContent:_textField.text withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                [SVProgressHUD showSuccessWithStatus:@"评论成功"];
                [self HideBox];
                [self loadDetailData:@"刷新中..."];
                _textField.text=@"";
            }else{
                [SVProgressHUD dismiss];
            }
        }];
    }else{
        //未登录,引导用户登录
        LoggingViewController *loginVC=[[LoggingViewController alloc] init];
        loginVC.ispresent=YES;
        [self presentViewController:loginVC animated:YES completion:^{
            
        }];
    }
}
 
/**
 显示评论框
 */
-(void)displayBox{
    [_replyMessageView setHidden:NO];
    [_textField becomeFirstResponder];
    [_tableView addGestureRecognizer:Tap];
}
 
/**
 隐藏评论框
 */
-(void)HideBox{
    [_textField resignFirstResponder];
    [_replyMessageView setHidden:YES];
    [_tableView removeGestureRecognizer:Tap];
}
 
/**
 返回
 */
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
 
/**
 添加评论
 
 @param sender 添加评论的按钮
 */
-(void)addCommits:(UIButton *)sender{
    NSLog(@"添加评论");
    [self displayBox];
}
 
/**
 查看全部评论
 
 @param sender 查看全部评论的按钮
 */
-(void)lookAllCommit:(UIButton *)sender{
    NSLog(@"查看全部评论");
    allCommentsViewController *allCommentsVC=[[allCommentsViewController alloc] init];
    allCommentsVC.goodsId=_goodsId;
    [self.navigationController pushViewController:allCommentsVC animated:YES];
}
 
-(void)gotoBuyGoods:(UIButton *)sender{
    NSString *goodsStr=[[_ItemDetailMessage objectForKey:@"Item"] objectForKey:@"Click_url"];
    [self openURL:goodsStr];
}
 
-(void)openURL:(NSString *)URL{
    // 判断当前系统是否有安装淘宝客户端
    if ([URL rangeOfString:@"taobao"].location !=NSNotFound) {
        //淘宝客户端
        NSString *agreement = [URL substringToIndex:5];
        NSString *httpsUrl = [URL stringByReplacingOccurrencesOfString:@"https" withString:@"tbopen"];
        NSString *httpUrl = [URL stringByReplacingOccurrencesOfString:@"http" withString:@"tbopen"];
        NSString *taobaoUrl = [agreement isEqualToString:@"https"]?httpsUrl:httpUrl;
        NSURL *url = [NSURL URLWithString:taobaoUrl];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            // 如果已经安装淘宝客户端,就使用客户端打开链接
            [[UIApplication sharedApplication] openURL:url];
        }else{
            [self openUrlWithBrowser:URL];
        }
    }else if([URL rangeOfString:@"tmall"].location !=NSNotFound){//天猫客户端
        NSString *agreement = [URL substringToIndex:5];
        NSString *httpsUrl = [URL stringByReplacingOccurrencesOfString:@"https" withString:@"tmall"];
        NSString *httpUrl = [URL stringByReplacingOccurrencesOfString:@"http" withString:@"tmall"];
        NSString *taobaoUrl = [agreement isEqualToString:@"https"]?httpsUrl:httpUrl;
        NSURL *url = [NSURL URLWithString:taobaoUrl];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            // 如果已经安装天猫客户端,就使用客户端打开链接
            [[UIApplication sharedApplication] openURL:url];
        }else{
            [self openUrlWithBrowser:URL];
        }
    }else{
        //内置浏览器
        [self openUrlWithBrowser:URL];
    }
}
 
/**
 内置网页视图打开网页
 
 @param url 网页地址
 */
-(void)openUrlWithBrowser:(NSString *)url{
    //    不能记住密码的方法
    
    //    WEBViewController *webVC=[[WEBViewController alloc] init];
    //    webVC.url=url;
    //    webVC.orMake=UIInterfaceOrientationMaskPortrait;
    //    [self presentViewController:webVC animated:YES completion:^{
    //
    //    }];
    
    //    可以记住淘宝密码的方法
//    id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
//    id<AlibcTradeService> service = [AlibcTradeSDK sharedInstance].tradeService;
//    AlibcTradeShowParams *showParams = [[AlibcTradeShowParams alloc] init];
//    
//    [service show:self.navigationController page:page showParams:showParams taoKeParams:nil trackParam:[self trackParams] tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
//        
//    } tradeProcessFailedCallback:^(NSError * _Nullable error) {
//        
//    }];
}
 
- (NSDictionary *)trackParams {
    return @{@"23594297": @"5de7c85d114a8ec635583a7c99200c9"};
}
 
/**
 点击收藏按钮
 
 @param sender 按钮
 */
-(void)clickCollectionBtn:(UIButton *)sender{
    if([sender isSelected]){
        sender.selected=NO;
        [[YTHNetInterface startInterface] cancelCollectWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                if ([result objectForKey:@"IsPost"]) {
                    sender.selected=NO;
                }else{
                    sender.selected=YES;
                }
            }else{
                sender.selected=YES;
            }
        }];
    }else{
        sender.selected=YES;
        [[YTHNetInterface startInterface] addCollectWithUid:[YTHsharedManger startManger].Uid WithSystem:@"1" withId:_goodsId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                if ([result objectForKey:@"IsPost"]) {
                    sender.selected=YES;
                }else{
                    sender.selected=NO;
                }
            }else{
                sender.selected=NO;
            }
        }];
    }
}
 
#pragma mark -UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if ([_RecommendListData count]>0) {
        return 3;
    }else{
        return 2;
    }
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==0) {
        return 1;
    }else if(section==1){
        return _commentMessage.count;
    }else if(section==2){
        return 1;
    }
    return 0;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section==0) {
        findTitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"findTitleTableViewCellID" forIndexPath:indexPath];
        NSDictionary *goodsItem=[_ItemDetailMessage objectForKey:@"Item"];
        cell.goodsName.text=[goodsItem objectForKey:@"Title"];
        cell.goodsPrice.text=[NSString stringWithFormat:@"¥%@",[goodsItem objectForKey:@"Zk_final_price"]];
        
        NSDictionary *UserMessage=[_ItemDetailMessage objectForKey:@"LoginUser"];
        [cell.userIcon setYthImageWithURL:[NSString stringWithFormat:@"%@%@",iconImageUrl,[UserMessage objectForKey:@"Portrait"]] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
        cell.userName.text=[UserMessage objectForKey:@"Nickname"];
        CGSize NameSize = [cell.userName.text boundingRectWithSize:CGSizeMake(KScreenW, 21) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
        //设置用户名的宽度
        if (NameSize.width>=KScreenW-130) {
            cell.userNameLength.constant=KScreenW-130;
        }else{
            cell.userNameLength.constant=NameSize.width+8;
        }
        
        if (_isCollection) {
            [cell.collectionBtn setSelected:YES];
        }
        int num=[[_ItemDetailMessage objectForKey:@"Collectcount"] intValue];
        if (_isCollection) {
            --num;
        }
        [cell.collectionBtn setTitle:[NSString stringWithFormat:@"收藏 %d ",num]forState:UIControlStateNormal];
        [cell.collectionBtn setTitle:[NSString stringWithFormat:@"收藏 %d ",num+1] forState:UIControlStateSelected];
        [cell.collectionBtn addTarget:self action:@selector(clickCollectionBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        [cell.toBuy addTarget:self action:@selector(gotoBuyGoods:) forControlEvents:UIControlEventTouchUpInside];
        
        return cell;
    }else if(indexPath.section==1){
        findcommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"findcommentTableViewCellID" forIndexPath:indexPath];
        NSDictionary *commentDic=[_commentMessage[indexPath.row] objectForKey:@"User"];
        NSString *tempIconStr=[commentDic objectForKey:@"Portrait"];//保存头像地址
        //判断头像地址是否为完整的地址
        if (tempIconStr.length>5) {
            if (![[tempIconStr substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {//不是完整的http地址
                tempIconStr=[NSString stringWithFormat:@"%@%@",iconImageUrl,[commentDic objectForKey:@"Portrait"]];
            }
            [cell.userIconImage setYthImageWithURL:tempIconStr placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
        }else{
            [cell.userIconImage setImage:[UIImage imageNamed:@"关注默认头像"]];
        }
        
        cell.userName.text=[commentDic objectForKey:@"Nickname"];
        cell.userTime.text=[[YTHNetInterface startInterface] getDate:[_commentMessage[indexPath.row] objectForKey:@"Createtime"]];
        cell.userContent.text=[_commentMessage[indexPath.row] objectForKey:@"Content"];
        return cell;
    }else{
        XYRChildTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XYRChildTableViewCellID" forIndexPath:indexPath];
        cell.cellDatas=_RecommendListData;
        cell.tableViewindex=indexPath;
        cell.clickIndexpath = ^(NSIndexPath *index){
            //点击猜你喜欢的商品,直接跳转淘宝或者天猫,再或者是网页,不用再出现现在的页面
            NSString *goodsStr=[_RecommendListData[index.row] objectForKey:@"Click_url"];
            [self openURL:goodsStr];
        };
        return cell;
    }
}
 
#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 195;
    }else if(indexPath.section==1){
        NSString *str=[_commentMessage[indexPath.row] objectForKey:@"Content"];
        CGSize commentSize = [str boundingRectWithSize:CGSizeMake(KScreenW-44, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
        return commentSize.height+65;
    }else if(indexPath.section ==2){
        if ([_RecommendListData count]%2==1) {
            return ((KScreenW-30)/2+50)*([_RecommendListData count]/2+1);
        }else{
            return ((KScreenW-30)/2+50)*[_RecommendListData count]/2;
        }
    }
    return 0;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(section==1){
        return 36;
    }else if(section==2){
        return 60;
    }
    return 0;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section==1) {
        return 40;
    }
    return 0;
}
 
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(section==1){
        UIView *HeaderView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 36)];
        HeaderView.backgroundColor=kGlobalBackgroundColor;
        //容器视图
        UIView *contentView=[[UIView alloc] initWithFrame:CGRectMake(10, 0, KScreenW-20, 36)];
        contentView.backgroundColor=[UIColor whiteColor];
        [HeaderView addSubview:contentView];
        //评论
        UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(8, 0, 40, 36)];
        titleLabel.font=[UIFont systemFontOfSize:15];
        titleLabel.text=@"评论";
        [contentView addSubview:titleLabel];
        //评论数量
        UILabel *numLabel=[[UILabel alloc] initWithFrame:CGRectMake(48, 0, 30, 36)];
        numLabel.font=[UIFont systemFontOfSize:15];
        numLabel.text=[NSString stringWithFormat:@"%d",(int)_commentMessage.count];
        numLabel.textColor=YTHColor(155, 125, 98);
        [contentView addSubview:numLabel];
        //查看全部
        UIButton * viewAll=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW-88-20, 0, 80, 36)];
        [viewAll setTitle:@"查看全部" forState:UIControlStateNormal];
        [viewAll setTitleColor:YTHColor(155, 125, 98) forState:UIControlStateNormal];
        [viewAll addTarget:self action:@selector(lookAllCommit:) forControlEvents:UIControlEventTouchUpInside];
        viewAll.titleLabel.font=[UIFont systemFontOfSize:15.0];
        [contentView addSubview:viewAll];
        //分割线
        UILabel *dividingLine=[[UILabel alloc] initWithFrame:CGRectMake(0, 35.5, KScreenW-36, 0.5)];
        dividingLine.backgroundColor=kGlobalBackgroundColor;
        [contentView addSubview:dividingLine];
        
        return HeaderView;
    }else if(section==2){
        UIView *HeaderView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 50)];
        HeaderView.backgroundColor=kGlobalBackgroundColor;
        
        //图片
        UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 10, 30, 30)];
        imageView.image=[UIImage imageNamed:@"商品猜你喜欢"];
        [HeaderView addSubview:imageView];
        
        //标题
        UILabel *titlelabel=[[UILabel alloc] initWithFrame:CGRectMake(50, 10, 85, 30)];
        titlelabel.text=@"猜你喜欢";
        titlelabel.font=[UIFont systemFontOfSize:15];
        [HeaderView addSubview:titlelabel];
        return HeaderView;
    }else{
        return nil;
    }
}
 
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section==1) {
        UIView *View=[[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, 40)];
        View.backgroundColor=kGlobalBackgroundColor;
        
        UIButton *addCommit=[[UIButton alloc] initWithFrame:CGRectMake(10, 0, KScreenW-20, 40)];
        [addCommit setTitle:@"添加评论" forState:UIControlStateNormal];
        [addCommit setTitleColor:YTHColor(183, 183, 183) forState:UIControlStateNormal];
        [addCommit addTarget:self action:@selector(addCommits:) forControlEvents:UIControlEventTouchUpInside];
        addCommit.backgroundColor=[UIColor whiteColor];
        addCommit.titleLabel.font=[UIFont systemFontOfSize:15.0];
        
        [View addSubview:addCommit];
        return View;
    }else{
        return nil;
    }
}
 
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
    return NO;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
 
#pragma mark -UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [_tableView setScrollEnabled:NO];
    return YES;
}
 
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    [self PostComment];
    return YES;
}
 
- (void)textFieldDidEndEditing:(UITextField *)textField{
    [_tableView setScrollEnabled:YES];
    _textField.placeholder=@"我也来说两句...";
}
 
#pragma mark 键盘隐藏
-(void)keyboardWillHide:(NSNotification *)notification{
    _replyMessageView.frame=CGRectMake(0, _tableView.frame.size.height-50, self.view.frame.size.width, 50);
}
#pragma mark 键盘出现
-(void)keyboardWasShown:(NSNotification *)notification{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到键盘的高度
    _replyMessageView.frame=CGRectMake(0, _tableView.frame.size.height-72-kbSize.height, self.view.frame.size.width, 50);
}
 
@end