What's the best way to update an image in my t

2020-05-07 19:17发布

问题:

Specifically, how do you get the image subview from a uitableview cell?

My table view gets data from the web asynchronously. When I created the image view the first time, I added the view by:

[imageView setImage:image];
[cell addSubview:imageView];

in tableView:cellForRowAtIndexPath:.

After new data is retrieved, I call reloadData to refresh the table view. But to update the image, I'd like to get a handle of this imageView (if it exist) and update the image.

My question is: Given the cell, is there a way to get this image view (handle) directly , or do I have to loop through the subviews to find the specific image view?

Any answer is highly appreciated!

Lu

回答1:

Set a tag on the imageView when you create it:

 [image viewSetTag: uniqueIntValue];

Then when you want to grab the view use:

UIView* recoveredImageView = [cell viewWithTag uniqueIntValue];