Sto impostando un'immagine, scaricata con sdwebimage, nel mio UITableViewCell
. Per evitare che UITableView
visualizzi immagini errate, è necessario impostare l'immagine su nil
in prepareForReuse
. Tuttavia, sto avendo qualche problema nell'implementazione di questo.Come implementare `prepareForReuse`?
Questo è dove ho impostato l'immagine:
- (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;
}
Quando implemento - (void)prepareForSegue
Xcode mantiene gettando errori dicendo che cell
non è disponibile ad esso. Qual è il modo corretto per implementare questo?
'prepareForReuse' è implementata sul' MGSwipeTableCell'. Qui, il riferimento alla cella è chiamato 'self' invece di' cell'. –
Ma se eseguo 'self.textLabel = nil', lancia' Proprietà 'textLabel' non trovata su oggetto di tipo 'ViewController'' – user4334509
Hai sbagliato 'prepareForSegue' sul tuo' ViewController' come l'implementazione di 'prepareForReuse' su il tuo 'MGSwipeTableCell'. Vai al tuo '@implementation MGSwipeTableCell' e implementa' prepareForReuse' lì. –