我有一个tableview,可以从Firebase加载数据库信息,并使用我的硬编码目录/文件从Firebase存储中提取图像。
我想要cell.videoID.text的值,以便我可以通过Segue将它传递给另一个viewcontroller。当单击单元格时,我似乎无法获得cell.videoID.text的值,并尝试了从此站点和其他站点的各种方法。
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return vehicleList.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell
let vehicle: VehicleModel
vehicle = vehicleList[indexPath.row]
cell.videoID.text = vehicle.id
cell.neworusedLabel.text = vehicle.neworused
cell.yearLabel.text = vehicle.year
cell.priceLabel.text = vehicle.price
cell.makeLabel.text = vehicle.make
cell.modelLabel.text = vehicle.model
cell.packageLabel.text = vehicle.package
cell.colorLabel.text = vehicle.color
// Get the image from storage container
let storage = Storage.storage().reference()
let imagePath = "tmpDir/tmpImage.png"
let tempImageRef = storage.child(imagePath)
tempImageRef.getData(maxSize: 1 * 600 * 600) { data, error in
if error == nil {
cell.lblView.image = UIImage(data: data!)
} else {
print(error?.localizedDescription)
}
}
return cell
}
var valueToPass:String!
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow!
let currentCell = tableView.cellForRow(at: indexPath)! as UITableViewCell
print("currentCell")
print("You selected cell #\(indexPath.row)!")
// valueToPass = "Trying to get the videoID"
performSegue(withIdentifier: "detailSegue", sender: self)
}
答案 0 :(得分:0)
我的回答是:valueToPass = vehicleList [indexPath.row] .id
感谢评论中的Kosuke!