gpt4 book ai didi

ios - UITableview单元格向下滚动不平滑

转载 作者:行者123 更新时间:2023-11-29 05:58:28 27 4
gpt4 key购买 nike

我正在寻找有关我的自定义 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"))

Alamofire图片:https://github.com/Alamofire/AlamofireImage

imageView.af_setImage(withURL: image path, placeholderImage: UIImage(named: "placeholderImage"))

关于ios - UITableview单元格向下滚动不平滑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54901369/

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