iOS 融云修改RCConversationListViewCo

2018-05-04  本文已影响640人  一只帅气的猿

随便做个笔记

- (void)willDisplayConversationTableCell:(RCConversationBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath {
    
    RCConversationCell *baseCell = (RCConversationCell *)cell;
    RCConversationModel *model = self.conversationListDataSource[indexPath.row];
    RCMessage *ms = (RCMessage *)model.lastestMessage;
    
    if (ms.extra != nil) {
        
        NSData *jsonData = [ms.extra dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        
        if ([dictionary[@"fromContactid"] integerValue] != 0) {

            //cell复用问题
            for (UIView *view in baseCell.contentView.subviews) {
                if ([view isKindOfClass:UIImageView.class] && view.tag == 120) {
                    [view removeFromSuperview];
                }
                if ([view isKindOfClass:UILabel.class] && view.tag == 110) {
                    [view removeFromSuperview];
                }
            }
            
            UIImageView *view = [[UIImageView alloc] init];
            view.tag = 120;
            [baseCell.contentView addSubview:view];
            view.translatesAutoresizingMaskIntoConstraints = NO;
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:baseCell.conversationTitle, @"view1", view,@"view", nil];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[view1]-15-[view(==30)]" options:0 metrics:nil views:dic]];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[view(==20)]" options:0 metrics:nil   views:NSDictionaryOfVariableBindings(view)]];
            
            UILabel *showLabel = [[UILabel alloc] init];
            showLabel.backgroundColor = [UIColor clearColor];
            showLabel.font = [UIFont systemFontOfSize:12];
            showLabel.tag = 110;
            [baseCell.contentView addSubview:showLabel];
            showLabel.translatesAutoresizingMaskIntoConstraints = NO;
            NSDictionary *showLabelDic = [NSDictionary dictionaryWithObjectsAndKeys:view, @"view1", showLabel,@"view",baseCell.messageCreatedTimeLabel,@"view2", nil];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[view1]-0-[view]-0-[view2]" options:0 metrics:nil views:showLabelDic]];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[showLabel(==20)]" options:0 metrics:nil   views:NSDictionaryOfVariableBindings(showLabel)]];
        
            if ([dictionary[@"fromContactid"] integerValue] == 1) {
                
                showLabel.text = @"她想和你视频";
                showLabel.textColor = RGBA(142, 74, 255, 1.0);
                
                NSMutableArray *ary=[NSMutableArray new];
                for(int I=1;I<=7;I++){
                    NSString *imageName=[NSString stringWithFormat:@"showGif%d",I];
                    UIImage *image=[UIImage imageNamed:imageName];
                    [ary addObject:image];
                }
                view.animationImages=ary;
                view.animationRepeatCount=0;
                view.animationDuration=1.0;
                [view startAnimating];
            }
            
            if ([dictionary[@"fromContactid"] integerValue] == 2) {
                
                showLabel.text = @"她距离你较近";
                showLabel.textColor = [UIColor redColor];
                
                NSMutableArray *ary=[NSMutableArray new];
                for(int I=1;I<=3;I++){
                    NSString *imageName=[NSString stringWithFormat:@"gifImage%d",I];
                    UIImage *image=[UIImage imageNamed:imageName];
                    [ary addObject:image];
                }
                view.animationImages=ary;
                view.animationRepeatCount=0;
                view.animationDuration=1.0;
                [view startAnimating];
            }
        
        }
        
        //cell复用问题
        for (UIView *view in baseCell.contentView.subviews) {
            if ([dictionary[@"fromContactid"] integerValue] == 0 && [view isKindOfClass:UIImageView.class] && view.tag == 120) {
                [view removeFromSuperview];
            }
            if ([dictionary[@"fromContactid"] integerValue] == 0 && [view isKindOfClass:UILabel.class] && view.tag == 110) {
                [view removeFromSuperview];
            }
        }
        
    } else {
        
        //cell复用问题
        for (UIView *view in baseCell.contentView.subviews) {
            if ([view isKindOfClass:UIImageView.class] && view.tag == 120) {
                [view removeFromSuperview];
            }
            if ([view isKindOfClass:UILabel.class] && view.tag == 110) {
                [view removeFromSuperview];
            }
        }
        
    }
    
    [cell layoutIfNeeded];
    
}

上一篇下一篇

猜你喜欢

热点阅读