iOS--當cell上顯示不同數量圖片的時候重用

來源:互聯網
上載者:User

標籤:

- (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];    }}

 

iOS--當cell上顯示不同數量圖片的時候重用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.