I'm setting an image, downloaded with sdwebimage, in my UITableViewCell
. In order, to keep the UITableView
from displaying wrong images, I need to set the image to nil
in prepareForReuse
. However, I'm having some trouble implementing this.
This is where I set the image:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * reuseIdentifier = @"programmaticCell";
MGSwipeTableCell * cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
CGFloat brightness = [UIScreen mainScreen].brightness;
cell.textLabel.text = [self.streams[indexPath.row] name];
cell.detailTextLabel.text = [self.streams[indexPath.row] published];
NSString *imageUrl = [NSString stringWithFormat: @"%@", [self.streams[indexPath.row] photo]];
NSLog(@"Image is: %@ and path is: %d", imageUrl, indexPath.row);
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]
placeholderImage:[UIImage imageNamed:@"tile-blue.png"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
cell.delegate = self; //optional
return cell;
}
When I implement - (void)prepareForSegue
Xcode keeps throwing errors saying that cell
is unavailable to it. What is the proper way to implement this?
Try adding this to your MGSwipeTableCell.m
:
-(void)prepareForReuse
{
[super prepareForReuse];
self.textLabel.text = @"";
self.detailTextLabel.text = @"";
self.imageView.image = nil;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With