gpt4 book ai didi

ios - 我如何实现 `prepareForReuse` ?

转载 作者:可可西里 更新时间:2023-11-01 03:29:28 26 4
gpt4 key购买 nike

我正在我的 UITableViewCell 中设置一个图像,使用 sdwebimage 下载。为了防止 UITableView 显示错误的图像,我需要在 prepareForReuse 中将图像设置为 nil。但是,我在实现时遇到了一些麻烦。

这是我设置图像的地方:

- (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;
}

当我实现 - (void)prepareForSegue 时,Xcode 不断抛出错误,指出 cell 对其不可用。实现它的正确方法是什么?

最佳答案

尝试将此添加到您的MGSwipeTableCell.m:

-(void)prepareForReuse
{
[super prepareForReuse];

self.textLabel.text = @"";
self.detailTextLabel.text = @"";
self.imageView.image = nil;
}

关于ios - 我如何实现 `prepareForReuse` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27929371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com