// // CommentCell.m // test12 // // Created by apple on 15/11/22. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "CommentCell.h" #import "UIImageView+WebCache.h" CommentCellStyle cellStyle; @implementation CommentCell - (void)awakeFromNib { [super awakeFromNib]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:NO animated:animated]; } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ([reuseIdentifier isEqualToString:@"school"]) { cellStyle = CommentCellStyleSchool; } self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.imageView.layer.masksToBounds = YES; self.backgroundColor = backGroundColor; UIButton* btn = [[UIButton alloc] init]; [btn setImage:[UIImage imageNamed:@"question_approve_checked_icon.png"] forState:UIControlStateSelected]; [btn setImage:[UIImage imageNamed:@"question_approve_icon.png"] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:btn]; [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; _upBtn = btn; [btn.imageView setContentMode:UIViewContentModeScaleAspectFit]; UIImageView* iv = [[UIImageView alloc] init]; [iv setContentMode:UIViewContentModeScaleAspectFit]; [self.contentView addSubview:iv]; honorIv = iv; UILabel* lb = [[UILabel alloc] init]; [self.contentView addSubview:lb]; [lb setTextColor:contentTextColor]; celDateLbl = lb; [celDateLbl setFont:[UIFont scaleSize:12]]; [self.textLabel setTextColor:kTitleColor]; [self.detailTextLabel setTextColor:subTitleColor]; } [self setSelectionStyle:UITableViewCellSelectionStyleNone]; return self; } +(CommentCell*)cellForTableView:(UITableView*)tableView Style:(CommentCellStyle )style { cellStyle = style; NSString* cellid; /**如果2个风格的cell,需要区分,可以在这设置 */ if (CommentCellStyleQuestion == style) { cellid= @"CommentCellIdentifier"; }else{ cellid= @"CommentCellIdentifier"; } CommentCell* cell = [tableView dequeueReusableCellWithIdentifier:cellid]; if (!cell) { cell = [[CommentCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid]; [cell setBackgroundColor:backGroundColor]; } return cell; } -(void)setCommentDic:(NSDictionary *)commentDic { _commentDic = commentDic; [self.imageView sd_setImageWithURL:[NSURL URLWithString:commentDic[@"PHOTO"]] placeholderImage:randomPortrait()]; [self.textLabel setText:commentDic[@"QC_NAME"]]; [self.detailTextLabel setText:commentDic[@"QC_DESC"]]; [_upBtn setTitle:commentDic[@"QC_UP_NUM"] forState:UIControlStateNormal]; [_upBtn setSelected:NO]; NSString* str = commentDic[@"QC_CRDATE"]; if (str && str.length >16) { [celDateLbl setText:[str substringToIndex:16]]; }else{ [celDateLbl setText:str]; } } -(void)setDict:(NSDictionary *)dict { _dict = dict; [_upBtn setTitle:dict[@"POINTNUM"] forState:UIControlStateNormal]; [_upBtn setSelected:NO]; self.imageView.contentMode = UIViewContentModeScaleAspectFit; self.imageView.clipsToBounds = YES; if (![dict[@"NAME"] isEqualToString:@""] && ![dict[@"NAME"] isEqualToString:@"暂无相关点评~"]) { _upBtn.hidden = NO; NSString *path = [Tools imageStringWithPhotoString:dict[@"PHOTO"] HeadImgString:dict[@"HEADIMG"] Type:2]; if (path.length < 1) { path = nil; } [self.imageView sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"portrait%d.png",arc4random()%10 + 1]]]; }else{ _upBtn.hidden = YES; } [self.textLabel setText:dict[@"NAME"]]; [self.detailTextLabel setText:[dict[@"PJCONTENT"] isEqualToString:@""]? @"点评内容为空" : dict[@"PJCONTENT"] ]; NSString* str = dict[@"PJSJ"]; if (str && str.length >11) { [celDateLbl setText:[str substringToIndex:11]]; }else{ [celDateLbl setText:str]; } } /**每次cell重用时,这里都会调用一次。 切记不要再这里创建视图。 */ -(void)layoutSubviews { [super layoutSubviews]; CGFloat font = 15; [self.detailTextLabel setNumberOfLines:0]; [self.detailTextLabel setFont:[UIFont scaleSize:font]]; CGFloat aWid = self.width; CGFloat x,w,h,y,bd; x = 5; w = h = 55; y = bd = 10; [self.imageView setFrame:CGRectMake(x, y, w, h)]; self.imageView.layer.cornerRadius = h/2.0; if (cellStyle == CommentCellStyleQuestion) { y += bd; x = x + w + bd; h = 25; [self.textLabel setFrame:CGRectMake(x, y, 260, h)]; y = y + h + bd; w = aWid - x - bd; h = [self.detailTextLabel.text heightForWid:w Font:font]; //现在主要是根据desc的内容动态设置宽高了 [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)]; y = y+h+bd; h = 30; [celDateLbl setFrame:CGRectMake(x, y, 260, h)]; [_upBtn setFrame:CGRectMake(aWid - 100, y, 100, h)]; [honorIv setFrame:CGRectMake(aWid - 55, 5, 55, 55)]; }else{ y += bd; x = x + w + bd; h = 25; [self.textLabel setFrame:CGRectMake(x, y, 180, h)]; y = y + h + bd; w = aWid - x - bd; h = [self.detailTextLabel.text heightForWid:w Font:font]; if (h < 40) { h = 40; } //现在主要是根据desc的内容动态设置宽高了 [self.detailTextLabel setFrame:CGRectMake(x, y, w, h)]; y = y+h+bd; h = 30; [celDateLbl setFrame:CGRectMake(x, y, 260, h)]; [_upBtn setFrame:CGRectMake(aWid - 100, y, 100, h)]; [honorIv setFrame:CGRectMake(aWid - 55, 5, 55, 55)]; } } -(void)btnClick:(UIButton*)sender { if ([_VCName isEqualToString:@"SearchComment"]) { //代表是驾校的页面 return; } [self UpLoadApproveComId]; } - (void)UpLoadApproveComId { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; NSString *comId = _commentDic ? _commentDic[@"QC_ID"] : _dict[@"ID"]; [arr property:comId forKey:@"cid"]; [arr property:@"1" forKey:@"type"]; if (myDelegate.isLogin) { [arr property:RQ_USER_MANAGER.currentUser._id forKey:@"userId"]; }else{ [arr property:@"匿名用户" forKey:@"userId"]; } NSString* method = @"updateQuestionUpOrDown"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { RemoveHUD(); if (!dict) { ShowMsg(@"操作失败"); return; } if ( [dict[@"code"] isEqualToString:@"1"]) { ShowMsg(dict[@"body"]); [_upBtn setSelected:YES]; return; } if ( [dict[@"code"] isEqualToString:@"0"]) { [LoadingView showMsg:@"点赞成功" Style:1]; } NSString *comUpNum = _commentDic ? _commentDic[@"QC_UP_NUM"] : _dict[@"POINTNUM"]; comUpNum = [NSString stringWithFormat:@"%d",comUpNum.intValue+1]; [_upBtn setTitle:comUpNum forState:UIControlStateNormal]; [_upBtn setSelected:YES]; }]; } @end