[英]Swift set image on TableView from retrieved firebase data
So the way I struct my retrieved data is by;所以我构造检索到的数据的方式是:
struct framePic { let imagedB : Data! struct framePic { let imagedB : 数据! let pricedB : String!
让 pricedB :字符串! }
}
I've managed to retrieve the data but I dont know how to set image on tableView?我设法检索了数据,但我不知道如何在 tableView 上设置图像? I've managed to figure it out with a label... but not with image?
我已经设法用标签弄清楚了……但不是用图像?
this is the code for the cell in the table;这是表格中单元格的代码;
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: RowCellTableView = myTableView.dequeueReusableCell(withIdentifier: "cell") as! RowCellTableView
// sets label
cell.priceView.text = framePics[indexPath.row].pricedB
// set image on UIimageView???
--- I dont know how to add this? I need somehow to get the list of only the images??? I believe if I had the array variable like; imageFiles[] I could have done;
imageFiles[indexPath.row].getDataInBackground... But in my case I use struct so how am I supposed to do this in this case?
the RowCellTableView just contains; RowCellTableView 只包含;
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var priceView: UILabel!
In your struct you have:在您的结构中,您有:
struct framePic {
let imagedB : Data!
let pricedB : String!
}
Try to convert the imagedB to UIImage like this:尝试将 imagedB 转换为 UIImage,如下所示:
var imageUIImage: UIImage = UIImage(data: imageData)
So your implementation would be like this:所以你的实现应该是这样的:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: RowCellTableView = myTableView.dequeueReusableCell(withIdentifier: "cell") as! RowCellTableView
// sets label
cell.priceView.text = framePics[indexPath.row].pricedB
// convert imageData to UIImage
var imageUIImage: UIImage = UIImage(data: framePics[indexPath.row].imagedB)
// apply image to UIImageView
cell.imageView.image = imageUIImage
return cell
}
cell.imageView.image = someImage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.