我正在尝试从我的 CollectionView 中的特定单元格开始,以便为每个单元格访问不同的 View Controller 。
我已经成功地找到了如何从一个单元格项目中继续。
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let selectedIndexPath = interests[indexPath.item]
performSegue(withIdentifier: "FeatureVC", sender: selectedIndexPath)
}
然而,事实证明,弄清楚如何从一个特定的单元格中分离出来更加困难。我看过一些答案,但似乎没有什么是非常直接的。
我是开发新手,所以我能理解这个问题是否有一个简单的解决方案,但这将是我应用程序主要功能的关键,所以我必须正确解决这个问题。
如果我能收到任何指导,我将不胜感激。
最佳答案
根据您的条件,您似乎使用了错误的委托(delegate),如果您只想搜索一个单元格,您可以检查 IndexPath.item
将 didDeselectItemAt
更改为 didSelectItemAtIndexpath
func collectionView(_ collectionView: UICollectionView, didSelectItemAtIndexpath indexPath: IndexPath) {
if indexPath.item == yourSpecificCellIndex {
//perform segue
}
}
关于ios - 如何访问 UICollectionView 和 Segue 中的特定单元格项目到新的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45441026/