Search code examples
swifttransitionuicollectionviewcell

Perform a segue programmatically


Hi I'm trying to perform a segue programmatically without the Storyboard. Currently I have this as my code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "popOutNoteExpanded" {
        let vc = segue.destination as! ExpandedCellViewController
        let cell = sender as! AnnotatedPhotoCell
        sourceCell = cell
        vc.picture = cell.imageView.image
        print("button pressed")
    }
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    performSegue(withIdentifier: "popOutNoteExpanded", sender: indexPath)
}

When I click on the collection view cell it's saying that:

has no segue with identifier 'popOutNoteExpanded'.

Not sure how to perform my custom animated transition.


Solution

  • Segues are components of storyboard. If you don't have a storyboard, you can't perform segues. But you can use present view controller like this:

    let vc = ViewController() //your view controller
    self.present(vc, animated: true, completion: nil)