UITableViewCell : UIImageView in ContentView overlaps images in iPhone SDK.
In my iPhone app, I am using a tableView and have added the imageView as ContentView in my tableViewcell.
At the click of button I am changing the tableView Contents. So every time I click a button it should show the corresponding image in tableViewCell.
Problem:
Suppose I am loading images 1.png, 2.png and 3.png in tableView on click of button A, B and C respectively.
Now let us consider that initially I clicked button A and 1.png appears. Now when I click the button B then 2.png appears but 1.png a开发者_运维知识库lso remains in background. So basically it overlaps the tableViewCell with a new image.
Troubleshooting I already have done:
1) I tried releasing imageView and setting imageView.image = nil;
2) I tried reloading the table and empty out table before each button click.
3) Even I tried putting the whole code in if(cell==nil) clause of cellForRowAtIndexPath
method
Have you tried clearing the cell's contentView?
for(UIView* subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
If you use three different imageViews then try to imgView1.hidden=FALSE;imgView.hidden=TRUE;imgView3.hidden=TRUE on button1 click event. same way for buttton2 and button3.
It seems that you have set the image in the (cell==nil) block. If yes please comment that out.
Do it like:
if(cell ==nil){
//add image view here.
}
UIImageView *imgView = (UIImageView *)[cell.contentView viewWithTag:ImgViewTag];
if(condition)
imgView.image = someImage;
else
imgView.image = nil;
I have got the answer and I am really thankful to Ben Gottlieb:
remove image from tableViewCell created programmatically
精彩评论