Ich stelle ein Bild, heruntergeladen mit sdwebimage, in meinem UITableViewCell
. Um die UITableView
davon abzuhalten, falsche Bilder anzuzeigen, muss ich das Bild auf nil
in prepareForReuse
festlegen. Allerdings habe ich einige Probleme damit, dies zu implementieren.Wie implementiere ich `prepareForReuse`?
Dies ist, wo ich das Bild gesetzt:
- (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;
}
Wenn ich - (void)prepareForSegue
Xcode implementieren hält Fehler werfen sagen, dass cell
es nicht verfügbar ist. Was ist der richtige Weg, dies zu implementieren?
'prepareForReuse' auf' MGSwipeTableCell' umgesetzt wird. Hier wird der Bezug auf die Zelle "self" anstelle von "cell" genannt. –
Aber wenn ich 'self.textLabel = nil' mache, wird' Property 'textLabel' nicht gefunden auf Objekt vom Typ 'ViewController'' – user4334509
Sie haben 'prepareForSegue' auf Ihrem' ViewController' als die Implementierung von 'prepareForReuse' an Ihre 'MGSwipeTableCell'. Gehen Sie zu Ihrer '@implementation MGSwipeTableCell' und implementieren Sie' prepareForReuse' dort. –