【发布时间】:2023-03-22 04:29:01
【问题描述】:
我正在尝试从我的 Firebase 存储中加载要在我的应用视图中显示的图像。
我主要有两门课
- 包含 tableView 的主“ClassView”。
- 自定义 tableViewCell - “ClassCell”(此类包括一个 imageView,我想在其中显示来自 firestore 的图片。- imageView 称为 classImage。
下面是tableView数据源扩展。
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.register(UINib(nibName: K.tableCellNibName, bundle: nil), forCellReuseIdentifier: K.tableCellIdentifier)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let storageRef = storage.reference()
let reference = storageRef.child(K.FStore.classImagesPath)
let placeholderImage = UIImage(named: "placeholder.png")
let imageView: UIImageView = self.imageView
let cell = tableView.dequeueReusableCell(withIdentifier: K.tableCellIdentifier, for: indexPath) as! ClassCell
//below is where I try to set the my image but it is not changing anything
cell.classImage?.sd_setImage(with: reference, placeholderImage: placeholderImage)
//This I tried to make sure that I am can access the image right and it worked just fine
// cell.classImage?.backgroundColor = .black
return cell
}
使用 sd_setImage 方法不显示图像。如果我的代码中有任何错误或在任何地方缺少声明,我们将不胜感激。
以下是我运行模拟器时得到的结果。这些黑框中显示的不是图像,而是空的。此外,imageView.image 返回 nil,所以很可能 sd_setImage 没有正确放置图像。
【问题讨论】:
-
这段代码实际上在做什么,而不是你所期望的?请编辑问题以使其更清晰,并包含您的调试详细信息。
-
确保您尝试访问的图像是 ios 支持的格式,而不是 SVG。
-
@Sreekuttan 它是 JPG 格式。所以我猜它是支持的
-
@DougStevenson 该代码未显示任何图像。只显示一个白框。当我尝试访问 imageView.image 时。它给零。将在问题中添加详细信息。
标签: swift firebase-storage sdwebimage