0
我有一个表格视图,它从Firebase加载数据库信息,并且图像从我的硬编码目录/文件从Firebase存储中拉出。从Firebase填充数组传递UITableViewCell数据
我想要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)
}
而你的'prepareForSegue'? –
在performSegue之前备份一行,这就是我卡住的地方。我无法在performSegue之前获得变量......所以prepareForSegue中的代码与此无关(但它适用于本项目中的其他10个vc)。 – user3534305
试试这个'valueToPass = vehicleList [indexPath.row] .id' –