How can I implement `prepareForReuse`?

I set the image uploaded using sdwebimage to my UITableViewCell . To keep the UITableView displaying invalid images, I need to set the nil image to prepareForReuse . However, I have some problems with this.

Here 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 not available to it. What is the correct way to implement this?

+7
ios objective-c uitableview
source share
1 answer

Try adding this to your MGSwipeTableCell.m :

 -(void)prepareForReuse { [super prepareForReuse]; self.textLabel.text = @""; self.detailTextLabel.text = @""; self.imageView.image = nil; } 
+10
source share

All Articles