我對如何將DownloadURL作爲鏈接並將其變成圖像並將其添加到我的tableview單元格中感到困惑?我在故事板中有一個imageview,不知道如何將它連接到tableview單元。謝謝!如何從URL中添加圖像到一個TableView中
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!
}
定義YOUT細胞的一類,並添加一個UIImageView作爲出口,然後在的cellForRowAtIndexPath使用圖像管理器,例如Alamofire或SDWebImage如果我的回答幫助加載圖像 –
,將其標記請(按jackdaw)讓其他人知道它是正確的 –