ios - Swift 4 TableView Cell 不显示正确的图像

标签 ios swift uitableview alamofire

当我滚动 tableView 时,UIImageView 没有显示正确的图像。我怎样才能在 swift 4 语言中正确完成此操作。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")

        //Transform Data From ^ to load at the bottom
        tableView.transform = CGAffineTransform (scaleX: 1,y: -1);
        cell?.contentView.transform = CGAffineTransform (scaleX: 1,y: -1);
        cell?.accessoryView?.transform = CGAffineTransform (scaleX: 1,y: -1);


        let username = cell?.viewWithTag(1) as! UITextView
        username.text = messageArray[indexPath.row].username

        let message = cell?.viewWithTag(2) as! UITextView
        message.text = messageArray[indexPath.row].message

        let timeStamp = cell?.viewWithTag(3) as! UILabel
        timeStamp.text = messageArray[indexPath.row].timeStamp

        let imageView = cell?.viewWithTag(4) as! UIImageView
        let urlString = messageArray[indexPath.row].photoUrl
        imageView.layer.cornerRadius = 10
        imageView.clipsToBounds = true

        //Load profile image(on cell) with URL & Alamofire Library
        let downloadURL = NSURL(string: urlString!)
        imageView.af_setImage(withURL: downloadURL! as URL)

        return cell!
    }

最佳答案

在 cellForRowAtIndexPath 方法的开头设置 imageView.image = nil。您正在重复使用细胞。有时您需要重置单元组件。

关于ios - Swift 4 TableView Cell 不显示正确的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49247175/

相关文章:

iOS objective-C : How to call Push Segue from another Class

ios - 单个 Viewcontroller 中的多个 UITableview

ios - 将 Realm Bool 数据分为 2 个部分 Tableview

ios - 表格 View 单元格接受文本输入?

swift - 自定义 UITableViewCell 中的 UIView 在滚动时重绘

iphone - 为 iPhone 应用程序制作手册的最简单和最快的方法是什么?

ios - UITableViewRowAction 与 UISwipeActionsConfiguration

iOS:通过 UIActivityViewController 共享不适用于 UIActivityItemSource

swift - 在 Swift 中重铸时,何时使用 "<object> as <type>"以及何时使用 <type>(<object>)

ios - Swift 语言多播委托(delegate)