问题
I 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
回答1:
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
来源:https://stackoverflow.com/questions/43328838/how-to-perform-segue-to-different-controllers-in-uicollectionview