What's the best way to update an image in my tableview image subview?

萝らか妹 提交于 2019-12-20 07:17:43

问题


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];


来源:https://stackoverflow.com/questions/6299391/whats-the-best-way-to-update-an-image-in-my-tableview-image-subview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!