zoukankan      html  css  js  c++  java
  • iOS--当cell上显示不同数量图片的时候重用

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        //标识符
        static NSString *iden = @"cardsCell";
        CardsCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
        Cards *cards = [self.cardsArr objectAtIndex:indexPath.row];
       //cell为空就创建
        if (cell == nil) {
            cell = [[CardsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
        }else {   //如果存在cell需要把之前添加的会变化的控件删除
            //删除cell上添加的图片
            [cell.photoGroup removeFromSuperview];
        }
    
        cell.cards = cards;;
        
        return cell;
    }

    在自定义cell里

    - (void)setCards:(Cards *)cards {
        if (_cards != cards) {
            _cards = cards;
        }
        //给cell控件赋值
        [self.avaImageView sd_setImageWithURL:[NSURL URLWithString:_cards.avaImageUrl] placeholderImage:[UIImage imageNamed:@"72tx.png"]];
        self.usernameLabel.text = _cards.username;
        self.commentLabel.text = [NSString stringWithFormat:@"%ld",_cards.replyArr.count];
        self.titleLabel.text = _cards.title;
        self.timeLabel.text = _cards.time;
        self.contextLabel.text = _cards.context;
        //判断图片数组数量,大于0就根据数量创建,否则不创建
        if (_cards.imageArr.count > 0) {
            //图片浏览,用了一个图片浏览器SDPhotoGroup,继承UIView
            self.photoGroup = [[SDPhotoGroup alloc] initWithFrame:CGRectMake1(0, 100, 105*_cards.imageArr.count, 60)];
            NSMutableArray *temp = [NSMutableArray array];
            [_cards.imageArr enumerateObjectsUsingBlock:^(NSString *src, NSUInteger idx, BOOL *stop) {
                SDPhotoItem *item = [[SDPhotoItem alloc] init];
                item.thumbnail_pic = src;
                [temp addObject:item];
            }];
            self.photoGroup.photoItemArray = [temp copy];
            [self.contentView addSubview:self.photoGroup];
        }
    }
  • 相关阅读:
    c# 改变FileUpload 上传文件大小
    使用ActiveX读取客户端mac地址
    javascript小技巧
    【2012百度之星/资格赛】H:用户请求中的品牌 [后缀数组]
    POJ1012 约瑟夫环问题[双向循环链表+打表技巧]
    北大ACM题分类
    ACM大量习题题库
    POJ1423 计算出n的阶乘的位数大数问题[Stirling公式]
    ACM训练计划(下)
    POJ2080 角度问题[cmath函数]
  • 原文地址:https://www.cnblogs.com/zhangshan/p/5157494.html
Copyright © 2011-2022 走看看