zoukankan      html  css  js  c++  java
  • 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];
    }
  • 相关阅读:
    win7下命令行添加系统服务
    java执行cmd命令
    grails-BuildConfig.groovy中grails.war.resources
    密码学
    Grails框架优劣势
    groovy+idea+Maven项目加载自身jar包
    cmd查看我的电脑盘符和文件
    MySQL insert插入
    MySQL截取字符串函数方法
    mysql 替换语句
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/7942471.html
Copyright © 2011-2022 走看看