I've got a UITableViewCell
that displays text and optional an image. When the image is displayed however, it becomes a bit buggy because in -(void)prepareForReuse:
I'm setting the imageCell
of the tableViewCell
to nil, and when scrolling the image needs to be loaded in every time.
In my customTableViewCell.m
, this is the code I use to prepare for reuse:
- (void)prepareForReuse {
[super prepareForReuse];
self.noteLabel.text = nil;
self.textLabel.text = nil;
self.imageCell.image = nil;
self.personImage = nil;
}
By deleting the row self.imageCell.image = nil;
some cells will duplicate the imageCell
from other UITableViewCells
, so I have to use the prepareForReuse
method.
Is there any way to not set the imageCell
to nil if it has an image when all the cells are loaded? I've tried
if(self.iamgeCell.image == nil){
self.imageCell.image = nil;
}
In which I tried saying: if the imageCell
was null before the reuse, please set it to nil when preparing for reuse, but that didn't work out so well.
This how I currently load the image in the cellForRowAtIndex
method:
PFFile *imageFile = [payment objectForKey:@"img"];
if(![imageFile isEqual:@""]){
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:imageData];
cell.imageCell.image = [self imageWithImage:image scaledToWidth:cell.imageCell.frame.size.width ];
}
}];
}