• iOS之UITableView加载网络图片cell自适应高度


    #pragma mark-  UITableView
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        UIImage *img = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:_productDetailImageAry[indexPath.row]];
        if (!img) {
            img =  [UIImage imageNamed:@"产品默认图"];
        }
        CGFloat height = img.size.height;
        return (height/img.size.width)*CScreenWidth;
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return _productDetailImageAry.count;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        MDSListImageCell   *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [self confirmCell:cell atIndexPath:indexPath];
        return cell;
    }
    - (void)confirmCell:(MDSListImageCell *)cell atIndexPath:(NSIndexPath *)indexPath{
        NSString *imgUrl = _productDetailImageAry[indexPath.row];
        UIImage *cachedImg = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:imgUrl];
        if (!cachedImg) {
            [self downloadImage:imgUrl forIndexPath:indexPath];
        }else{
            cell.imageShow  =cachedImg;
        }
    }
    - (void)downloadImage:(NSString *)imageURL forIndexPath:(NSIndexPath *)indexPath{
        __weak typeof(self) weakSelf = self;
        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:SDIMAGE_URL(imageURL)
                                                              options:2
                                                             progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                                                             }
                                                            completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
                                                                [[SDImageCache sharedImageCache] storeImage:image forKey:imageURL toDisk:YES];
                                                                [weakSelf performSelectorOnMainThread:@selector(reloadCellAtIndexPath:) withObject:indexPath waitUntilDone:NO];
                                                                
                                                            }];
    }
    -(void)reloadCellAtIndexPath:(NSIndexPath *)indexPath {
        [_listTableView reloadData];
    }
  • 相关阅读:
    怎么安装Python?
    Ramnit蠕虫病毒分析和查杀
    Exphub[漏洞利用脚本库]
    SMBv3远程代码执行漏洞复现(CVE-2020-0796)
    Tomcat AJP 文件包含漏洞复现(CVE-2020-1938)
    Fastjson远程代码执行漏洞复现
    信息收集之——旁站、C段
    Redis未授权访问漏洞复现与利用
    CSS
    MVC控制器路由
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/7942471.html
Copyright © 2020-2023  润新知