0

I have a DetailViewController that has a container view. The first container view that will appear is the DetailChildViewController.

The DetailChildViewController consists of a collection view which will display the child view's properties. However, even if I assign data onto the properties of the detailChildVC in the prepare(for segue:) function, the properties variable in the DetailChildViewController still returns nil. How do I fix this?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Set the currentViewController to description child VC because that is the first one
        // shown in the container view
        if segue.identifier == "DetailChildSegue" {
            let detailChildVC = DetailChildViewController()
            // Set product of the childVC
            let actionArray = [product?.action.keys.description] as? [String]
            detailChildVC.properties = actionArray
        }
        // Set the currentVC
        currentVC = segue.destination
    }
Abdelahad Darwish
  • 5,969
  • 1
  • 17
  • 35

1 Answers1

0

You assign to a new var DetailChildViewController() not the destination

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "DetailChildSegue" {

        let detailChildVC = segue.destination as! DetailChildViewController

        let actionArray = [product?.action.keys.description] as? [String]

        detailChildVC.properties = actionArray
    }

    // Set the currentVC

    currentVC = segue.destination
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • This is great! Thank you for this. I just found out though that let actionArray = [product?.action.keys.description] as? [String] does not give me an array of key string objects. Do you know how I can fix this? – Julienne Lim May 26 '18 at 20:29