2017-08-17 45 views
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) 
} 
+0

而你的'prepareForSegue'? –

+0

在performSegue之前備份一行,這就是我卡住的地方。我無法在performSegue之前獲得變量......所以prepareForSegue中的代碼與此無關(但它適用於本項目中的其他10個vc)。 – user3534305

+0

試試這個'valueToPass = vehicleList [indexPath.row] .id' –

回答

0

我的回答是:valueToPass = vehicleList [indexPath.row] .ID

由於耿介以上的評論!