iOS 数目不定的图片加载在页面上面

注意:[list.picsArray count]是指解析出来的图片数目,但是并不确定

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

{

    static NSString *CellIdentifier = @"Cell";

    ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    ListModel *list = (ListModel *)[dataArray objectAtIndex:indexPath.row];

    if (cell == nil) {

        cell = [[[NSBundle mainBundle] loadNibNamed:@"ListCell" owner:self options:nil] lastObject];

        for (int i = 0; i < [list.picsArray count]; i++) {

            UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10+i*110, 115, 80, 60)];

            leftImageView.tag = i+100;

            [cell.contentView addSubview:leftImageView];

        }

   }

   

    cell.NameLabel.text = list.name;

    [cell.IconImageView setImageWithURL:[NSURL URLWithString:list.iconUrl]];

    cell.DetailLabel.text = list.detailInfo;

    cell.DateLabel.text = list.date;

    for (int i = 0; i < [list.picsArray count]; i++) {

        UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:i+100];

        [imageView setImageWithURL:list.picsArray [i]];

    }

    return cell;

 }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS开发中,如果你需要在应用程序中加载网络图片,特别是从HTTP协议切换到HTTPS,可以利用URLSession或者第三方库如SDWebImage等来处理这种跨协议的转换。以下是一个基本的过程: 1. **NSURLSession**: 使用`NSURLSessionDataTask`发起网络请求时,你可以创建一个代理(如NSURLSessionDelegate),当接收到服务器返回的状态码为403 (禁止访问) 或者其他明确表示需要升级到安全协议的情况时,动态修改URL为 HTTPS。 ```swift let task = URLSession.shared.dataTask(with: URL(string: "http://example.com/image.jpg")!) { ... } task.resume() ``` 在完成数据任务的回调中检查响应并相应地更新URL: ```swift if let response = task.response as? HTTPURLResponse { if response.statusCode == 301 || response.statusCode == 302 && response.url?.scheme == "http" { let httpsUrl = response.url!.absoluteString.replacingOccurrences(of: "http:", with: "https:") task.cancel() return URLSession.shared.dataTask(with: URL(string: httpsUrl)) { ... }.resume() } } ``` 2. **SDWebImage**: 如果你在使用SDWebImage库,它通常会处理这类转换。只需在配置SDWebImageOptions时开启 `SDWebImageHandleRedirects`,SDWebImage就会自动处理从HTTP到HTTPS的跳转。 ```swift let imageUrl = URL(string: "http://example.com/image.jpg") imageView.sd_setImage(with: imageUrl, options: .handleRedirects) ``` **相关问题--:** 1. SDWebImage库是什么时候引入对HTTP到HTTPS自动转换的支持的? 2. 使用NSURLSession手动处理这种转换有哪些局限性? 3. 有没有其他的第三方库也支持这种特性?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值