[英]UITableview cell scrolling down not smooth
我正在寻找有关自定义UITableview单元格图像的解决方案。
我在自定义UITableview单元中正常加载了一些信息(标签+ UIimageview),但由于iOS 12,当我向下滚动时,它并不平滑(第一次滚动时滞后,而当我向下滚动时,它却平滑向上滚动,可能与缓存图片有关)。
RecipeTableCell *cell = (RecipeTableCell *)[self.UITableView
dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil)
{
cell = [[RecipeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Display recipe in the table cell
Recipe *recipe = nil;
recipe = [recipes objectAtIndex:indexPath.row];
recupereNomFavoris = [[recipes objectAtIndex:indexPath.row] valueForKey:@"favoris"];
recupereImage = [[recipes objectAtIndex:indexPath.row] valueForKey:@"image"];
recupereNom = [[recipes objectAtIndex:indexPath.row] valueForKey:@"name"];
recupereLien = [[recipes objectAtIndex:indexPath.row] valueForKey:@"lien"];
recupereGenre = [[recipes objectAtIndex:indexPath.row] valueForKey:@"genre"];
}
}
//Display cells informations
cell.nameLabel.text = recipe.name;
cell.genre.text = recipe.genre;
cell.thumbnailImageView.image = [UIImage imageNamed:recipe.image];
我尝试添加异步解决方案,但加载图像需要1秒钟以上的时间。
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageNamed:recipe.image];// Load from file or Bundle as you want
dispatch_sync(dispatch_get_main_queue(), ^{
cell.thumbnailImageView.image = image;
});
});
所有图像的大小都在1到20kb之间,我将它们本地加载。 我在我的IB中使用约束(重量和宽度+布局约束)。
我尝试实现SDWEBIMAGE,但它仅允许您加载URL图像。
有什么建议么 ? 我正在努力解决这个问题
在这种情况下,图像会导致您需要使用图像延迟加载的错误,您可以使用以下库代码来设置延迟加载,这样做的好处是您可以通过为图像分配UIimageview来设置占位符图像,
SDWebimage: https : //github.com/SDWebImage/SDWebImage
import SDWebImage
imageView.sd_setImage(with: your image path or data, placeholderImage: UIImage(named: "placeholder.png"))
AlamofireImage: https : //github.com/Alamofire/AlamofireImage
imageView.af_setImage(withURL: image path, placeholderImage: UIImage(named: "placeholderImage"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.