码迷,mamicode.com
首页 > 其他好文 > 详细

tableview代理里面添加图片

时间:2016-07-28 15:39:11      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

for (UIView *cellView in cell.subviews){

            [cellView removeFromSuperview];

        }

避免图片出现问题

 

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        

    }else{

        for (UIView *cellView in cell.subviews){

            [cellView removeFromSuperview];

        }

    }

    

    if (indexPath.row %2 == 0) {

        //cell.backgroundColor =[UIColor redColor];

    }

    cell.backgroundColor =[UIColor clearColor];

    NSDictionary *dict = [_resultArray objectAtIndex:indexPath.row];

    

    //创建头像

    UIImageView *photo ;

    

    if ([[dict objectForKey:@"name"]isEqualToString:@"rhl"]) {

        //我

        

        photo = [[UIImageView alloc]init];//WithFrame:CGRectMake(WIDTH- WIDTH*40/320, cell.bounds.size.height, WIDTH*30/320, WIDTH*30/320)];

        photo.layer.masksToBounds =YES;

        photo.layer.cornerRadius =15;

        [cell addSubview:photo];

        [photo mas_makeConstraints:^(MASConstraintMaker *make) {

            make.size.mas_equalTo(CGSizeMake(30, 30));

            make.right.equalTo(@(-10));

            make.bottom.equalTo(@(-20));

        }];

        photo.image = [UIImage imageNamed:@"headImage10.jpg"];

        photo.backgroundColor =[UIColor yellowColor];

        if ([[dict objectForKey:@"content"] isEqualToString:@"0"]) {

            [cell addSubview:[self yuyinView:1 from:YES withIndexRow:indexPath.row withPosition:WIDTH*25/320]];

            

        }else{

            [cell addSubview:[self bubbleView:[dict objectForKey:@"content"] from:YES withPosition:WIDTH*65/320]];

        }

        

    }else{

        //对方

        photo = [[UIImageView alloc]initWithFrame:CGRectMake(10,15,30,30)];

        photo.layer.masksToBounds =YES;

        photo.layer.cornerRadius =15;

        [cell addSubview:photo];

        photo.image = [UIImage imageNamed:@"headImage2.jpg"];

        photo.backgroundColor =[UIColor blackColor];

        if ([[dict objectForKey:@"content"] isEqualToString:@"0"]) {

            [cell addSubview:[self yuyinView:1 from:NO withIndexRow:indexPath.row withPosition:WIDTH*25/320]];

        }else{

            [cell addSubview:[self bubbleView:[dict objectForKey:@"content"] from:NO withPosition:WIDTH*65/320]];

        }

    }

    

    return cell;

    

}

tableview代理里面添加图片

标签:

原文地址:http://www.cnblogs.com/kewang1993/p/5714806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!