Reputation: 9
How can I adjust a UITableViewCell's
height dynamically based on the height of an image downloaded from an API?
I tried to use tableView:cellForRowAtIndexPath:indexPath
but failed.
FYI, I am using AFNetworking to get the images' url from api and I use SDWebImage to get the image data.
Upvotes: 0
Views: 343
Reputation: 23882
Set height from heightForRowAtIndexPath
method.
-(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;
}
}
See the answer related to it.
Upvotes: 0