私はUITableViewCell
にsdwebimageでダウンロードした画像を設定しています。 UITableView
に間違った画像が表示されないようにするには、nil
の画像をprepareForReuse
に設定する必要があります。しかし、私はこれを実装するいくつかの問題を抱えています。私は画像設定場所です`prepareForReuse`はどのように実装しますか?
:私は- (void)prepareForSegue
Xcodeのを実装する場合
- (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;
}
はcell
がそれに利用できないというエラーを投げ続けます。これを実装する適切な方法は何ですか?あなたのMGSwipeTableCell.m
にこれを追加すること
'prepareForReuse'があなたの' MGSwipeTableCell'に実装されています。ここでは、セルへの参照を 'cell'ではなく' self'と呼びます。 –
'self.textLabel = nil'を実行すると' Property 'textLabel'が 'ViewController'型のオブジェクトに見つかりません。' – user4334509
'prepareForReuse'の実装として' ViewController'に 'prepareForSegue'と間違っていますonあなたの 'MGSwipeTableCell'。 '@implementation MGSwipeTableCell'に行き、そこで' prepareForReuse'を実装してください。 –