Skip to main content

UICollectionViewCell Segue

When using a UICollectionView, you may want to pass data from one controller to another when a user clicks on the collection view cells. In order to do this, we need to find the item that has been clicked on.

With the uicollectionview and segue setup within the storyboard, you can use the prepareForSegue function to find the selected cell from the sender as shown below in the code extract.

Once you have the indexPath you are then able to get any relevant data from you collections using indexPath.row and pass that to the awaiting view controller.

As you will see above, the awaiting controller here has an embeded navigation controller, so we use this as the segue destination controller and then take the topViewController as our awaiting controller.

Please follow and like us: