如何在一个tableview单元格中显示多个图像?我从webservices获取图像

时间:2016-04-26 13:36:54

标签: ios xcode

enter image description here

(
    (
        "http://sportsromio.aiminfotechs.com/WEBSERVICES/available_sports/volleyball.png",
        "http://sportsromio.aiminfotechs.com/WEBSERVICES/available_sports/football.png"
    ),
(
    "http://sportsromio.aiminfotechs.com/WEBSERVICES/available_sports/football.png",
    "http://sportsromio.aiminfotechs.com/WEBSERVICES/available_sports/cricket.png"
)

我使用这个数组我该如何使用它。

2 个答案:

答案 0 :(得分:1)

将此代码放入'cellForRowIndexPath'

int x = 0;

        for (NSURL * url in yourArrayName) {
            UIImageView *yourImageView =[[UIImageView alloc] initWithFrame:CGRectMake(x,50,20,20)];
            yourImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
            [cell addSubview:yourImageView];

            x = x + 60;
        }

答案 1 :(得分:0)

为行添加单元格

int x = 0;
    for (NSString * stringurl in [imgs objectAtIndex:indexPath.row]) {
        UIImageView *yourImageView =[[UIImageView alloc] initWithFrame:CGRectMake(x,10,40,40)];
        NSURL *url=[NSURL URLWithString:stringurl];

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

        [yourImageView sd_setImageWithURL:url
                          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;
                                 }];


        [cell addSubview:yourImageView];

        x = x + 40;
    }