I try to send a data from my collection view cell to my static table view like the picture below. so if the user touch that colorful circular image collection view cell, the app will show the facilitiy detail. the UI should be like this
here is the code I use in the collection view VC (FacilitiesVC) to send the to static table view controller
extension FacilitiesVC : UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
selectedFacility = facilityCategory[indexPath.section].member[indexPath.row]
performSegue(withIdentifier: "toFacilitiesDetailVC", sender: nil)
}
}
extension FacilitiesVC {
//MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toFacilitiesDetailVC" {
guard let facilitiesDetailVC = segue.destination as? FacilitiesDetailVC else {return}
facilitiesDetailVC.facilitiesDetailData = selectedFacility
}
}
}
and here is the code in my static table view controller
class FacilitiesDetailVC: UITableViewController {
@IBOutlet weak var locationLabel: UILabel!
var facilitiesDetailData : FacilitiesPS? {
didSet {
updateUI()
}
}
}
extension FacilitiesDetailVC {
// MARK: - Helper Methods
func updateUI() {
guard let data = facilitiesDetailData else {return}
print( "the facility data : \(data)")
locationLabel.text = data.location
}
}
extension FacilitiesDetailVC {
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
}
but I got nil value in the updateUI()
, as you can see in updateUI()
, I try to print the value. the value is there, not nil (see the debugging area). but I got nil value when assign it to the label