Nazmul Hasan Nazmul Hasan - 1 year ago 73
iOS Question

"func prepareForSegue" not calling for Colection View

I don't know what am I missing?

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let poke:Pokemon!

if inSearchMode {
} else {
shouldPerformSegueWithIdentifier("PokemonDetailVC", sender: poke);

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "PokemonDetailVC" {
if let detailVC = segue.destinationViewController as? PokemonDetailVC{
if let poke = sender as? Pokemon {

Storyboard segue reference

enter image description here

enter image description here

Answer Source


performSegueWithIdentifier("Identifier", sender: self)

Instead of:

shouldPerformSegueWithIdentifier("Identifier", sender: self)

When we use shouldPerformSegueWithIdentifier we can catch the movement of segue with following method:

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool

Check this link: Prevent segue in prepareForSegue method?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download