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

Ios 使用ImageSlideshow播客时显示上一个tableview单元格中的重复图像,ios,swift,iphone,xcode,uitableview,Ios,Swift,Iphone,Xcode,Uitableview,这是我的回答,哪种媒体是我希望在tableview的幻灯片视图中水平显示的图像: 但是突然我发现我在同一个tableview行的视图中重复了这样的图像,我没有一个单元格的所有图片,你知道它可能来自可重复使用的单元格!!可能是从阵列中,我突然重复了一遍,得到了图像!!: 滚动时单元格中的图像数增加 我不知道为什么这是我的代码may会帮你的 在表格视图的cellForRowAt中: 您可以将其添加到PicCell类中 override func prepareForReuse() {

这是我的回答,哪种媒体是我希望在tableview的幻灯片视图中水平显示的图像:



但是突然我发现我在同一个tableview行的视图中重复了这样的图像,我没有一个单元格的所有图片,你知道它可能来自可重复使用的单元格!!可能是从阵列中,我突然重复了一遍,得到了图像!!:

滚动时单元格中的图像数增加
我不知道为什么这是我的代码may会帮你的



在表格视图的cellForRowAt中:
您可以将其添加到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
}

谢谢你解决了你真的帮了我大忙兄弟^^你能给我解释一下关于prepare FroReuseAbleCell以及为什么我从数组中删除了项吗如果UITableViewCell对象是可重用的,也就是说,它有一个重用标识符,在从UITableView方法DequeueReuseAbleCell(带标识符:)返回对象之前调用此方法。出于性能原因,您应该只重置与内容无关的单元格属性,例如alpha、编辑和选择状态。在重用单元格时,tableView中的表视图的委托(uu: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
    }
override func prepareForReuse() {
    super.prepareForReuse()
    self.slideShowImage.setImageInputs([])
    self.postImages.removeAll()
}
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
}