如何在tableview单元格中显示多个图像?

时间:2016-07-01 07:42:04

标签: ios objective-c uitableview uiscrollview sdwebimage

截图:
http://i.stack.imgur.com/g1ss2.png

我在此视图中使用SDWebImage库图像显示在此列表中但是当我滚动tableview时我不知道为什么但是这个单元格中的图像数据被更改而不需要的数据意味着图像显示在单元格中。 我用这个代码.....

for (NSString *stringurl in [[[ArrObj objectAtIndex:indexPath.row]valueForKey:@"feed_replies"]valueForKey:@"thumb_img"]) {

        UIImageView *yourImageView =[[UIImageView alloc] initWithFrame:CGRectMake(x,5,20,20)];
        NSURL *urlimg=[NSURL URLWithString:stringurl];

//        [yourImageView sd_setImageWithURL:urlimg
//                         placeholderImage:[UIImage imageNamed:@"placeholder"] options:indexPath.row ? SDWebImageRefreshCached : 0];
//        

                __block UIActivityIndicatorView *activityIndicator;
                __weak UIImageView *weakImageView = yourImageView;

                [yourImageView sd_setImageWithURL:urlimg
                                  placeholderImage:[UIImage imageNamed:@"placeholder"]
                                           options:SDWebImageProgressiveDownload
                                          progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                                              if (!activityIndicator) {
                                                  [weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
                                                  activityIndicator.center = weakImageView.center;
                                                  [activityIndicator startAnimating];
                                              }
                                          }
                                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                             [activityIndicator removeFromSuperview];
                                             activityIndicator = nil;
                                         }];
        weakImageView.layer.cornerRadius = weakImageView.frame.size.width / 2;;
        weakImageView.clipsToBounds = YES;
        weakImageView.tag=indexPath.row;

   //     yourImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:urlimg]];
        [cell.cmtprofilescroll addSubview:yourImageView];

        x = x + 30;

0 个答案:

没有答案
相关问题