繁体   English   中英

使用 ImageSlideshow pod 时显示上一个 tableview 单元格中的重复图像

[英]showing duplicated images from previous tableview cell when using ImageSlideshow pod

这是我的回复,哪些媒体是我想在幻灯片视图中水平显示在表格视图中的图像:


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 class

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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM