Ich bin verwirrt darüber, wie ich die DownloadURL, die ein Link ist, nehmen und es in ein Bild verwandeln und es in meiner Tableview-Zelle hinzufügen kann? Ich habe eine Bildansicht in meinem Storyboard und weiß auch nicht, wie ich es mit der Tableview-Zelle verbinden soll. Vielen Dank!Wie füge ich ein Bild in einer TableView von URL
override func viewDidLoad() { super.viewDidLoad()
let ref = FIRDatabase.database().reference().child("Posts")
ref.observeSingleEvent(of: .value, with: { snapshot in
print(snapshot.childrenCount)
for rest in snapshot.children.allObjects as! [FIRDataSnapshot] {
guard let value = rest.value as? Dictionary<String,Any> else { continue }
guard let downloadURL = value["DownloadURL"] as? String else { continue }
let post = postStruct(title: title, date: date, author: author, article: article, 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 label1 = cell?.viewWithTag(1) as! UILabel
label1.text = posts[indexPath.row].title
return cell!
}
eine Klasse für yout Zelle, definieren und eine UIImageView als Auslass fügen Sie dann in der cellForRowAtIndexPath ein Bild loader verwenden wie Alamofire oder SDWebImage Ihr Bild –
zu laden, wenn meine Antwort geholfen, sie markieren Bitte (Dohle drücken), um andere wissen zu lassen, dass es korrekt ist. –