// // TopicComCell.m // jiaPei // // Created by apple on 15/12/7. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "TopicComCell.h" @interface TopicComCell () /**显示-》回复XXX:***** */ @property(nonatomic,strong) UILabel *lblContent; /**回复按钮.为了设置frame。才保留的引用。 */ @property(nonatomic,strong) UIButton *btnCom; /**采纳按钮.为了设置frame。才保留的引用。 */ @property(nonatomic,strong) UIButton *btnAdopt; @end @implementation TopicComCell - (void)awakeFromNib { // Initialization code [super awakeFromNib]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } +(TopicComCell*)cellForTableView:(UITableView*)tableView { NSString* cellid; cellid= @"TopicComCellIdentifier"; TopicComCell* cell = [tableView dequeueReusableCellWithIdentifier:cellid]; if (!cell) { cell = (TopicComCell*)[[TopicComCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid]; [cell.textLabel setTextColor:kTitleColor]; [cell.detailTextLabel setTextColor:contentTextColor]; UILabel* lbl = [[UILabel alloc] init]; [lbl setFont:[UIFont scaleSize:17]]; [cell addSubview:lbl]; cell .lblContent = lbl; lbl.numberOfLines = 0; [cell.lblContent setTextColor:subTitleColor]; UIButton* btn = [[UIButton alloc] init]; [cell addSubview:btn]; cell.btnCom = btn; [btn setImage:[UIImage imageNamed:@"community2.png"] forState:UIControlStateNormal]; [btn addTarget:cell action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; cell.btnAdopt = [[UIButton alloc] init]; [cell addSubview:cell.btnAdopt]; cell.btnAdopt.layer.masksToBounds = YES; cell.btnAdopt.layer.cornerRadius = 15; UIColor *myColor = [UIColor colorWithRed:207/255.0 green:207/255.0 blue:207/255.0 alpha:1]; cell.btnAdopt.layer.borderColor = myColor.CGColor; cell.btnAdopt.layer.borderWidth = 1; [cell.btnAdopt setTitle:@"采纳" textColor:myColor font:12 fotState:UIControlStateNormal]; [cell.btnAdopt addTarget:cell action:@selector(btnClickToAdopt:) forControlEvents:UIControlEventTouchUpInside]; } return cell; } -(void)setModel:(NSDictionary *)model { _model = model; //评论的头像地址 NSString *headImg = model[@"HEADIMG"]; if (headImg && ![headImg hasPrefix:@"http"]){ headImg = [imgPreFix stringByAppendingString:headImg]; } //dansonimg [self.imageView sd_setImageWithURL:[NSURL URLWithString:headImg] placeholderImage:randomPortrait()]; if (_isAdopt) { [self.btnAdopt setHidden:NO]; if ([model[@"ACCEPT"] integerValue] > 0) { [self.btnAdopt.layer setBorderColor:defGreen.CGColor]; [self.btnAdopt setTitleColor:defGreen forState:UIControlStateNormal]; self.btnAdopt.tag = 7; }else{ UIColor *myColor = [UIColor colorWithRed:207/255.0 green:207/255.0 blue:207/255.0 alpha:1]; [self.btnAdopt.layer setBorderColor:myColor.CGColor]; [self.btnAdopt setTitleColor:myColor forState:UIControlStateNormal]; self.btnAdopt.tag = 0; } }else{ [self.btnAdopt setHidden:YES]; } [self.textLabel setText:model[@"STUNAME"]]; [self.detailTextLabel setText:model[@"ADDTIME"]]; NSString * str = model[@"REPLYUSERNAME"]; if (!str || [str isEqualToString:@""]) { [self.lblContent setText:model[@"CONTENT"]]; }else{ [self.lblContent setText:[NSString stringWithFormat:@"回复%@:%@",str,model[@"CONTENT"]]]; } } -(void)layoutSubviews { [super layoutSubviews]; CGFloat wid = self.frame.size.width; CGFloat x,y,w,h,bd; bd = 10; w = h = 50; x = y = bd; self.imageView.frame = CGRectMake(x, y, w, h); self.imageView.layer.cornerRadius = w/2.0; self.imageView.layer.masksToBounds = YES; x += bd+w; w = wid - x - bd - 30; h /= 2.0; self.textLabel.frame =CGRectMake(x, y, w, h); y+= h; self.detailTextLabel.frame =CGRectMake(x, y, w, h); w = wid - x - bd; y += bd + h; h = [_lblContent.text heightForWid:w Font:17]+bd; _lblContent.frame =CGRectMake(x, y, w, h); y = bd + 10; w = h = 30; x = kSize.width - bd - w; self.btnCom.frame = CGRectMake(x, y, w, h); x = kSize.width - 2*bd - 2*w; self.btnAdopt.frame = CGRectMake(x, y, w, h); } -(void)btnClick:(UIButton*)sender { if ([_delegate respondsToSelector:@selector(gotoCommentsByName:)]) { // NSLog(@"对评论的回复-----><>%@",_model); [_delegate gotoCommentsByName:_model[@"CRUSER"]]; } } -(void)btnClickToAdopt:(UIButton*)sender { if (sender.tag == 7) { ShowMsg(@"请勿重复采纳"); return; } [self uploadTopicAdopt]; } -(void)uploadTopicAdopt { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray* arr = [NSMutableArray array]; [arr addPro:@"user" Value:defUser.sfzmhm]; [arr addPro:@"commentId" Value:_model[@"ID"]]; NSString* method = @"uploadTopicCommentReply"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { if (!root) { ShowMsgFailed(); } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg([NSString stringWithFormat:@"%@",root[@"body"]]); } [self.btnAdopt.layer setBorderColor:defGreen.CGColor]; [self.btnAdopt setTitleColor:defGreen forState:UIControlStateNormal]; }]; } @end CGFloat TopicComCellHeight(NSDictionary* dict ) { CGFloat h = [dict[@"CONTENT"] heightForWid:(kSize.width - 80) Font:17]+10; return 80 + h; }