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];
    }
  • 相关阅读:
    springMVC的自定义类型的转换器
    pl/sql
    oracle中的函数
    Oracle基础
    跳台阶算法题
    红黑树
    优先队列
    堆排序
    H5页面,输入框的光标,如果页面上下滑动光标停留在页面上,除了输入框外,松手过了一段时间才跑回输入框里面
    正则:判断为数字,输入的金额整数位不得超过9位,小数位不得超过2位!
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/7942471.html
Copyright © 2011-2022 走看看