【发布时间】:2020-04-22 11:26:15
【问题描述】:
我正在使用 swift 开发一个应用程序。我正在加载带有来自 firebase 的图像的集合视图。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "subPostCell", for: indexPath) as! SubPostCell
cell.subPostImage.downloadImage(from: self.subposts[indexPath.row].pathToImage)
return cell
}
它在cell.subPostImage 行中给出错误:
无法转换类型“[String]?”的值到预期的参数类型“字符串?”
这是我的子帖子对象:
import Foundation
struct SubPost: Decodable {
var pathToImage: [String]?
var postID: String!
var userID: String!
init(pathToImage: [String]? = nil, postID: String? = nil, userID: String? = nil) {
self.pathToImage = pathToImage
self.postID = postID
self.userID = userID
}
}
这是我的 subpostscell 代码:
import UIKit
class SubPostCell: UICollectionViewCell {
@IBOutlet weak var stepLabel: UILabel!
@IBOutlet weak var subPostImage: UIImageView!
}
我做错了什么?
【问题讨论】:
-
错误很清楚发生了什么,它说它需要一个字符串?要在您使用时传递的是传递一个字符串数组?,即您的 pathToImage。很可能您需要将数组的字符串连接成一个字符串。
-
是的,但是每个 supbost 都有一个类似于“缩略图”的主要 url,其他的是其他东西。我需要下载其他网址,而不是缩略图。
标签: swift firebase firebase-realtime-database