UITableViewCell image not updating

I can update detailTextLabel.text, and the UITableViewCell shows the changes at runtime, but if I try to update imageView.image, it will not change the visible image. Any idea on why? I tried to call the update in UITableViewCell specifically, but to no avail.

-(void)getImageForURL:(NSURL*)url row:(UITableViewCell*)cell { UIImage*image; image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]; cell.imageView.image = image; // Does not work.. cell.detailTextLabel.text = @"test"; // Works } 
+4
source share
4 answers

Make sure the cell style is UITableViewCellStyleDefault, because other types of cells can always return nil imageView instead of creating one on demand.

+1
source

Try calling [cell setNeedsLayout] after setting the image, if this is the first image you set for the cell.

+22
source

Check for a null picture. If its nil, then the image is not extracted from the URL correctly.

0
source

I had problems adding an image to my imageView, which was limited to a table view cell and not updated using setneedslayout (). calling update methods for the table after adding the image helped me:

 cell.setNeedsLayout() if #available(iOS 11.0, *) { tableView.performBatchUpdates(nil, completion: nil) } else { tableView.beginUpdates() tableView.endUpdates() } 
0
source

All Articles