use*_*509 7 objective-c uitableview ios
我正在设置一个用sdwebimage下载的图像UITableViewCell.为了,为了保持UITableView从显示错误的图像,我需要将图像设置为nil在prepareForReuse.但是,我在实现这个方面遇到了一些麻烦.
这是我设置图像的地方:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
当我实现- (void)prepareForSegueXcode不断抛出错误,说它cell不可用.实现这个的正确方法是什么?
尝试将此添加到您的MGSwipeTableCell.m:
-(void)prepareForReuse
{
[super prepareForReuse];
self.textLabel.text = @"";
self.detailTextLabel.text = @"";
self.imageView.image = nil;
}
Run Code Online (Sandbox Code Playgroud)