-1

enter image description hereI want to segue to different controllers based on selection in UICollectionView :

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    if indexPath.item == 0 && indexPath.section == 0 {

    print ("Item 0 and section 0 selected")

        Perform Segue to Controller1 


    } else if (indexPath.item == 1 && indexPath.section == 0 ){

        ----> Perform Segue to Controller 2 


        print ("Item 1 and section 0 selected")
    } else {
        print("Not selected ")
    }



}

Based on selection in Collection View it should segue to Different UiCollectionView Controllers

Tried this command

self.performSegue(withIdentifier: "Selection1", sender: self)

But it errored out : 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier ProductCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

What is the best way to perform this kind of Segue ? Please advise

Thanks

Guri S
  • 1,083
  • 11
  • 12
  • Ummm... `performSegueWithIdentifier: sender:`? – crizzis Apr 10 '17 at 16:58
  • Possible duplicate of [IOS - How to segue programmatically using swift](http://stackoverflow.com/questions/27604192/ios-how-to-segue-programmatically-using-swift) – Daniel Legler Apr 10 '17 at 18:26
  • HI , i tried using the option given in the above link but I Got this error , 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier ProductCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' – Guri S Apr 11 '17 at 02:16
  • self.performSegue(withIdentifier: "Selection1", sender: self) --Tried this command – Guri S Apr 11 '17 at 02:17

1 Answers1

0

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    if indexPath.item == 0 && indexPath.section == 0 {




        self.performSegue(withIdentifier: "Selection1", sender: self)







    } else if (indexPath.item == 1 && indexPath.section == 0 ){


     self.performSegue(withIdentifier: "Selection2", sender: self)

        print ("Item 1 and section 0 selected")
    } else {
        print("Not selected ")
    }



}

Also in order to get rid of error i had to update the Identifier in Collection Reusable View enter image description here

Guri S
  • 1,083
  • 11
  • 12