Search code examples
iosswiftcosmicmindprepareforreuse

Passing Data using transition for UICollectionView


I am trying to implement something like the Photo View Collection using Cosmic Mind's Material framework in Swift 4.1.

In traditional segue, I can do something like this to pass data from 1 VC to another,

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "nextVC" {
            let destinationVC = segue.destination as! NextViewController
            destinationVC.scoreInt = score
            destinationVC.dataSource = list
        }
    } 

The only line of code in charge of swapping view controllers I see is this,

toolbarController?.transition(to: PhotoViewController(index: indexPath.item))

How can I pass data same as prepare for segue. Is there any delegate method to implement to get that functionality?


Solution

  • In the segue you are getting an instance of your view controller and then setting properties. You can do exactly that in the sample line, actually the index parameter is doing that in the constructor. You would only need to prepare and pass the data before you call the transition method. Once the data is passed, then you can pass the view controller to the transition method, and the data is then available to that controller.