0

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

enter image description here enter image description here

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

enter image description here

and here is the print in my debugging area enter image description here

what went wrong in here? I have already connect the label enter image description here

sarah
  • 3,819
  • 4
  • 38
  • 80
  • 1
    Your label isn't connected to its outlet. – rmaddy May 23 '18 at 02:18
  • I think that I have already connected it https://i.stack.imgur.com/IsZdF.png – sarah May 23 '18 at 02:22
  • Check it at runtime using the debugger a be sure. – rmaddy May 23 '18 at 02:24
  • sir I am a beginner, I don't understand what you mean check at runtime using debugger to be sure it has already connected or not. could you please give little bit information about this? :( – sarah May 23 '18 at 02:26
  • Sorry but teaching you how to use the debugger can't be done in a simple comment (and that's not what Stack Overflow is for). Since it is a very important skill to have as a programmer. I kindly suggest you take some time and find a good tutorial on the subject. The time spent now will save you countless hours and grief as you learn to program. Please take this as the friendly advice it is intended to be. – rmaddy May 23 '18 at 02:34
  • 1
    Thanks for the advice, will learn about debugger :) , I finally find out the problem, I should trigger the updateUI on viewdidload, not in observing properties. – sarah May 23 '18 at 02:37

0 Answers0