Tôi đang đặt hình ảnh, được tải xuống bằng sdwebimage, trong số UITableViewCell
. Để giữ UITableView
hiển thị hình ảnh sai, tôi cần đặt hình ảnh thành nil
trong prepareForReuse
. Tuy nhiên, tôi đang gặp một số vấn đề khi thực hiện điều này.Làm cách nào để triển khai `prepareForReuse`?
Đây là nơi tôi đặt hình ảnh:
- (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;
}
Khi tôi thực hiện - (void)prepareForSegue
Xcode giữ ném lỗi nói rằng cell
là không có sẵn cho nó. Cách thích hợp để thực hiện điều này là gì?
'prepareForReuse' được thực hiện trên' của bạn MGSwipeTableCell'. Ở đây, tham chiếu đến ô được gọi là 'self' thay vì' ô'. –
Nhưng nếu tôi làm 'self.textLabel = nil', nó ném' Property 'textLabel' không tìm thấy trên đối tượng kiểu 'ViewController'' – user4334509
Bạn đã nhầm lẫn 'prepareForSegue' trên' ViewController' của bạn khi thực hiện 'prepareForReuse' trên 'MGSwipeTableCell' của bạn. Đi đến '@implementation MGSwipeTableCell' của bạn và triển khai' prepareForReuse' ở đó. –