【发布时间】:2017-08-17 01:58:24
【问题描述】:
我有一个表格视图,它从 Firebase 加载数据库信息,并使用我的硬编码目录/文件从 Firebase 存储中提取图像。
我想要 cell.videoID.text 的值,以便我可以通过 Segue 将它传递给另一个视图控制器。单击单元格时,我似乎无法获得 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)
}
【问题讨论】:
-
你的
prepareForSegue? -
在 performSegue 之前备份一行,这就是我卡住的地方。我无法在 performSegue 之前获取变量...因此 prepareForSegue 中的代码与此无关(但它适用于我在此项目中拥有的其他 10 个 vc)。
-
试试这个
valueToPass = vehicleList[indexPath.row].id -
就是这样!!!我错过了一个事实,即我在一侧将其称为 videoID,而在另一侧称为 id!非常感谢!!
标签: ios swift uitableview firebase