I have a CollectionView
inside ViewController
and it doesn't perform segue to the second ViewController
My code is below:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard segue.identifier == "showFood" else { return }
guard let destination = segue.destination as? FoodViewController else { return }
destination.food = sender as? Food
}
extension AllFoodViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "showFood", sender: food[indexPath.row])
}
Also, I have this function in ViewDidLoad
private func configureCollectionView() {
collectionView.delegate = self
collectionView.dataSource = self
}
1- Call the function which configures the collection view methods in viewDidLoad()
2- Make sure that you've connected it like the image below:
3- Don't forget to write the segue identifier in the view controller like the image below: