我做错什么了?一切正常,但我没有图像,救命!谢谢!

import UIKit
import Firebase
import FirebaseDatabase
import SDWebImage

struct postStruct {
    let title : String!
    let downloadURL : String!

}

class ZeroHomeViewController: UITableViewController {
    var posts = [postStruct]()

    override func viewDidLoad() {
        super.viewDidLoad()
        let ref = Database.database().reference().child("Posts")
        ref.observeSingleEvent(of: .value, with: { snapshot in

            print(snapshot.childrenCount)

            for rest in snapshot.children.allObjects as! [DataSnapshot] {

                guard let value = rest.value as? Dictionary<String,Any> else { continue }
                guard let  title = value["Title"] as? String else { continue }
                guard let  downloadURL = value["Download URL"] as? String else { continue }
                let post = postStruct(title: title, downloadURL: downloadURL)
                self.posts.append(post)
            }

            self.posts = self.posts.reversed(); self.tableView.reloadData()

        })
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return posts.count
    }

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

        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        let imageView = cell?.viewWithTag(200) as! UIImageView

        imageView.sd_setImage(with: URL(string: "downloadUrl"), placeholderImage: UIImage(named: "placeholder.png"))

        let label1 = cell?.viewWithTag(1) as! UILabel
        label1.text = posts[indexPath.row].title
        return cell!
    }
}

最佳答案

其次
替换此行
imageView.sd_setImage(带:URL(字符串:“downloadUrl”),占位符image:UIImage(命名:“placeholder.png”))
带着这个
imageView.sd_setImage(带:URL(字符串:“www.domain.com/URL”),占位符image:UIImage(命名:“placeholder.png”))
确保编辑所需图像的url

关于swift - SDWebImage不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44530922/

10-14 22:29
查看更多