tags:

views:

20

answers:

1

I have an object that return a cached image view (UIImageView), which do the loading, showing the loading image, and then populate the view with the loaded image.

In my case, the TableView shows multiple rows, where the same user photo might appears more than once, and I noticed that because it is cached, it shown in the last cell it is been added to. I've tried to construct the UIImageView each time the table ask for a cell, it works, so the problem is with the cached image view!, but i don't know why! hints?

A: 

I don't know if I did understand your problem.

So to resume, your problem is that the UIImageView in your cell is "always" the same ?

In TableView you need to "remove" UIImage from UIImageView if you use the same "reusable" cell. In the cell construction you create the UIImageView and add it to the cell.

if (NEED_CREATE_CELL) {

  // create UIImageView etc

} else {

  // Set nil to the image property of the UIImageView
  // Like doing [ (UIImageView*)[ cell viewWithTag:80 ] setImage:nil ];

}

Does it answer to your question ^^?

Vinzius
Not exactly! In my case, the User object retain a reference to an UIImageView, and create it once, and then reuse it. In the TableView, if the user posted two comments for example, then his photo must appears in the two rows (two comments), what is happening is it is appears in the second row, not the first one. So the last cell get rendered show the photos! It is weird. When i changed the method implementation that returns the UIImageView to create a new UIImageView each time it is called, then each row (comments) show the UIImageView. Dose that clarifies the problem?
yeah I think I understand. The problem is that a UIView (so UIImageView) can't be at two position at the same time. Your best solution is to retain (for the user) the UIImage (no the UIImageView), and then change de image from de UIImageView property for each row ;-)
Vinzius
Thanks, I will see how I can do that, since I'm using the UIImageView so that it will show the tmp image while loading the right image from the server, and then update the UIImage.image value!
Yeah I think it's the better way for your problem. Good Luck ! (think to approve the answer if it helped ;-))
Vinzius
I moved the logic of loading the image from the UIImageView to an ImageLoader, and then construct a new UiImageView (subclass) each time with a reference to the loader, and it did work! But why can't UIView be in more than one place? And thanks a lot for the answer :-)
Think about it like a real object. When you move it, his place changed ^^ You can use it to do thing at different place, but you can't show it a different place except if you duplicate it ^^
Vinzius
Thanks again :), you made my day ...