UICollectionView 无法识别点击

UICollectionView does not recognise tap

我在 ViewController 里面有一个 CollectionView 并且它没有执行到第二个 ViewController

我的代码如下:

 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])
}

另外,我在ViewDidLoad里有这个功能

    private func configureCollectionView() {
    collectionView.delegate = self
    collectionView.dataSource = self
}

App design

Segue connection

1-调用viewDidLoad()

中配置集合视图方法的函数

2- 确保您已按照下图连接它:

3- 不要忘记在视图控制器中写入 segue 标识符,如下图所示:

4- 确保启用了用户交互