ios - 使用 ImageSlideshow pod 时显示上一个 tableview 单元格中的重复图像
问题描述
这是我的回复,哪个媒体是我想在幻灯片视图中水平显示在 tableview 中的图像:
media": [
{
"id": 555,
"postId": 274,
"media": "https://onebusinessqrcode.s3.us-east-2.amazonaws.com/b885b600-2d2c-5d84-aa64-259e946763e9.png",
"createdAt": "2021-05-22T04:01:03.351Z",
"updatedAt": "2021-05-22T04:01:03.351Z"
},
{
"id": 554,
"postId": 274,
"media": "https://onebusinessqrcode.s3.us-east-2.amazonaws.com/81a71835-1808-5d16-b9ff-062a345a9612.png",
"createdAt": "2021-05-22T04:01:03.154Z",
"updatedAt": "2021-05-22T04:01:03.154Z"
}
]
但突然我发现我在同一 tableview 行的视图中重复了这样的图像,我没有一个单元格的所有这些图片,你知道它可能来自可重复使用的单元格!可能是从数组中我突然重复了它的图像!!:
滚动时单元格中的图像数量增加
// arr to store all images I got from server to show them
var postImages = [SDWebImageSource]()
在 tableView 的 cellForRowAt 中:
//Configure the cell...
let postText = ArraysModel.posts[indexPath.row]
if let pictureString = postText.media {
let cell = tableView.dequeueReusableCell(withIdentifier: "PicCell", for: indexPath) as! PicCell
cell.postTextLabel.text = postText.postText
for image in pictureString {
let sources = SDWebImageSource(urlString: image.media ?? "")
if let sdImages = sources {
postImages.append(sdImages)
}
}
cell.slideShowImage.setImageInputs(postImages)
cell.slideShowImage.contentScaleMode = UIViewContentMode.scaleAspectFill
cell.slideShowImage.activityIndicator = DefaultActivityIndicator()
cell.slideShowImage.delegate = self
return cell
}
解决方案
你可以在你的 PicCell 类中添加这个
override func prepareForReuse() {
super.prepareForReuse()
self.slideShowImage.setImageInputs([])
self.postImages.removeAll()
}
像这样改变你的tableview委托方法
let postText = ArraysModel.posts[indexPath.row]
if let pictureString = postText.media {
let cell = tableView.dequeueReusableCell(withIdentifier: "PicCell", for: indexPath) as! PicCell
cell.postTextLabel.text = postText.postText
cell.prepareForReuse()
for image in pictureString {
let sources = SDWebImageSource(urlString: image.media ?? "")
if let sdImages = sources {
postImages.append(sdImages)
}
}
cell.slideShowImage.setImageInputs(postImages)
cell.slideShowImage.contentScaleMode = UIViewContentMode.scaleAspectFill
cell.slideShowImage.activityIndicator = DefaultActivityIndicator()
cell.slideShowImage.delegate = self
return cell
}
推荐阅读
- deep-learning - 在 Flux 和 Julia 中为 CNN 输入文本数据格式
- c - 这个问题有什么算法方法吗?
- powershell - Powershell unregister-ScheduledTask
- javascript - 运行实际应用程序时运行 jest 测试时的 Javascript 堆栈跟踪 VS 堆栈跟踪
- javascript - 我可以在 javascript 中使用模板文字来处理必须是单行的长文本,并且为了*可读性*它是多行的吗?
- node.js - 我们是否应该在 Typescript for Node 中使用类,或者我们在 javascript 导出函数开发中使用的相同方式
- javascript - 如何在 JSPDF 中编辑 TextField() 的字体大小?
- javascript - 省略等待让方法并行运行是否安全?
- sql-server - T-SQL n 行表示 2 天之间的天数
- sql - SQL Merge - 仅插入特定列已更新的位置