【问题标题】:iOS7 Adjust TableViewCell's height dynamically based on the height of image downloaded from APIiOS7根据从API下载的图像高度动态调整TableViewCell的高度
【发布时间】:2015-06-30 13:17:45
【问题描述】:

如何根据从 API 下载的图像的高度动态调整 UITableViewCell's 高度?

我尝试使用tableView:cellForRowAtIndexPath:indexPath,但失败了。

仅供参考,我使用 AFNetworking 从 api 获取图像的 url,我使用 SDWebImage 获取图像数据。

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:

heightForRowAtIndexPath 方法设置高度。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIImage *image = (UIImage *)[tableImageDict objectForKey:
                                 [NSString stringWithFormat:@"%i,%i",
                                  indexPath.row,indexPath.section]];


    if (image != nil)
    {
        return image.size.height; // you can set your size by taking from sdwebimage
    }
    else{
        return 44.0;
    }
}

查看与之相关的answer

【讨论】:

    猜你喜欢
    • 2020-11-23
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多