在我安装了最新的 Mojave macOS 之后,我刚刚将我的 Xcode 升级到了 10.2 版。
Xcode 要求我将 Swift 从 3.0 迁移到更高版本,所以我选择更新到 Swift 5.0。
在对语法更改进行一些小的更改后,该应用程序已启动并运行。但是,我发现collectionView didSelectItemAtIndexPath 在模拟器或设备中停止工作,这意味着当您点击collectionView 中的某个项目时,不再调用相应的didSelectItemAtIndexPath 方法。
我多次检查了我的代码更改,我很确定语法更改与受影响的 collectionViews 无关。我可以制作一些 TagGesture 技巧来解决,但我想知道这里有什么问题。
我很确定集合视图允许用户交互,也允许选择。
这里发生了什么?
更新:
我的旧代码在迁移后完全没有变化,它看起来像这样:
func collectionView(_ collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: IndexPath) {
...
}
我根据回答者的建议更新了以下内容。但是,仍然无法正常工作。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
...
}
(我什至没有触摸xib文件,代表都正确。)