ios - 如何访问 UICollectionView 和 Segue 中的特定单元格项目到新的 View Controller

标签 ios swift xcode uicollectionview uicollectionviewcell

我正在尝试从我的 CollectionView 中的特定单元格开始,以便为每个单元格访问不同的 View Controller 。

我已经成功地找到了如何从一个单元格项目中继续。

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
        
    let selectedIndexPath = interests[indexPath.item]
        
    performSegue(withIdentifier: "FeatureVC", sender: selectedIndexPath)
        
}

这是我当前代码的图片 Code.

然而,事实证明,弄清楚如何从一个特定的单元格中分离出来更加困难。我看过一些答案,但似乎没有什么是非常直接的。

我是开发新手,所以我能理解这个问题是否有一个简单的解决方案,但这将是我应用程序主要功能的关键,所以我必须正确解决这个问题。

如果我能收到任何指导,我将不胜感激。

最佳答案

根据您的条件,您似乎使用了错误的委托(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/

相关文章:

android - 在 <div> 中显示 AR 浏览器。是否可以?

ios - Firebase:第二次调用 setUserID() 似乎不起作用

ios - 在swift中调用objective-c类方法

ios - 如何验证我的应用程序是否支持 iOS 4.3

ios - Facebook SDK 是否使用 IDFA 进行移动应用安装?

ios - 自定义 CALayer 子类未显示

swift - swift 如何将文本文件转为字符串或数组?

swift - 将相等性定义为引用类型的标识?

ios - 如何执行 whereKey 以便查询距当前用户____公里远的帖子?

c++ - 静态变量链接错误