【问题标题】:UICollectionViewCell NavigationUICollectionViewCell 导航
【发布时间】:2016-06-26 14:04:34
【问题描述】:

我正在用 Swift 开发一个 iOS 应用程序。

我创建了一个 UICollectionViewController。我已经用图像填充了 UICollectionViewCells。如何将单个单元格与不同的 ViewController 连接,例如,如果我点击第一个单元格,它们将显示下一个 ViewController(但新的 ViewController 不需要来自单元格的数据,内容完全不同。我只会打开下一个视图控制器和这个用于 UiCollectionView 中的每个图像。

使用 prepareforsegue 时,我遇到的问题是,当我点击同一个 ViewController 显示的每个图像时。我希望每个图像都打开一个不同的新 ViewController。我需要哪个功能

【问题讨论】:

    标签: ios swift uicollectionview segue


    【解决方案1】:

    Segue 定义了它们要转换到的 viewController。如果每个单元格需要转到不同的 viewController,那么您需要为每个单元格设置一个 segue。

    1. UICollectionViewController 顶部的 viewController 图标连接你的 segues,而不是从原型单元格连接:

    2. Attributes Inspector中为每个segues赋予一个唯一标识符:

    3. collectionView(_:didSelectItemAtIndexPath:) 中,使用indexPath 选择正确的segue 标识符并调用performSegueWithIdentifier(_:sender:)

      override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
          let segues = ["goToVC1", "goToVC2", "goToVC3"]
          let segueID = segues[indexPath.item]
          performSegueWithIdentifier(segueID, sender: self)
      }
      

    【讨论】:

    • 非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-14
    相关资源
    最近更新 更多