UICollectionView在prepareForSegue中获取indexPath

squarehippo10

对于我的集合视图我用didSelectItemAt打电话performSegue我的问题是发件人是我的vc,而不是单元本身。因此,在prepareForSegue中,出现错误,因为我无法将vc转换为单元格类型。

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
   performSegue(withIdentifier: "collectionSegue", sender: self)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
   if let destinationVC = segue.destination as? ImageViewController {
      let cell = sender as! ImageCollectionViewCell 
      let indexPath = imageCollectionView.indexPath(for: cell)
      destinationVC.buttonTag = indexPath?.row
   }
}
用户名

您可以将发件人设置为任意内容。这可能会有所帮助:

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
       let cell = collectionView!.cellForItemAtIndexPath(indexPath) as! ImageCollectionViewCell
       performSegue(withIdentifier: "collectionSegue", sender: cell)
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在prepareForSegue中获取indexpath

来自分类Dev

在indexPath中快速使用prepareForSegue

来自分类Dev

在 indexPath 处获取 UISwitch 状态到 UIcollectionView

来自分类Dev

在UICollectionView中永远不会调用prepareForSegue

来自分类Dev

在prepareForSegue中获取UIPopoverController参考?

来自分类Dev

在UICollectionView中重新加载indexPath.row

来自分类Dev

从RoboVM中的indexPath获取行

来自分类Dev

在UITableViewCell子类中获取indexPath

来自分类Dev

如何获取位于UICollectionView中心的单元格的indexPath

来自分类Dev

iOS:UICollectionview,如何通过indexPath获取单元格的contentoffset

来自分类Dev

prepareForSegue collectionView indexPath使用Swift

来自分类Dev

重置uicollectionview的indexPath

来自分类Dev

重置uicollectionview的indexPath

来自分类Dev

在tableView中获取Section indexPath的行

来自分类Dev

使用Swift在UITableViewCell中获取UITextField的indexPath

来自分类Dev

如何从Swift中的indexPath获取UITableViewCell对象?

来自分类Dev

使用Swift在UITableViewCell中获取UITextField的indexPath

来自分类Dev

如何获取indexPath并在NSMutableArray中写入

来自分类Dev

cellForItemAtIndexPath 获取块中 indexPath 的错误值

来自分类Dev

iOS:UICollectionview,如何通过它的indexPath获取单元格的contentoffset

来自分类Dev

如何在prepareForSegue中获取启动segue的按钮?

来自分类Dev

如何在prepareForSegue中获取启动segue的按钮?

来自分类Dev

在UITableView中获取核心数据对象的indexPath

来自分类Dev

iOS 7-如何从放置在UITableViewCell中的按钮获取indexPath

来自分类Dev

如何从tableView中获取索引号:cellForRowAtIndexPath:使用`indexPath`参数?

来自分类Dev

获取嵌入在UITableViewCell中的UITable的单元格的indexPath

来自分类Dev

在单元格中获取 indexPath.row

来自分类Dev

prepareForSegue UICollectionView不起作用(快速)

来自分类Dev

获取UICollectionView中Scroll的总高度?

Related 相关文章

  1. 1

    如何在prepareForSegue中获取indexpath

  2. 2

    在indexPath中快速使用prepareForSegue

  3. 3

    在 indexPath 处获取 UISwitch 状态到 UIcollectionView

  4. 4

    在UICollectionView中永远不会调用prepareForSegue

  5. 5

    在prepareForSegue中获取UIPopoverController参考?

  6. 6

    在UICollectionView中重新加载indexPath.row

  7. 7

    从RoboVM中的indexPath获取行

  8. 8

    在UITableViewCell子类中获取indexPath

  9. 9

    如何获取位于UICollectionView中心的单元格的indexPath

  10. 10

    iOS:UICollectionview,如何通过indexPath获取单元格的contentoffset

  11. 11

    prepareForSegue collectionView indexPath使用Swift

  12. 12

    重置uicollectionview的indexPath

  13. 13

    重置uicollectionview的indexPath

  14. 14

    在tableView中获取Section indexPath的行

  15. 15

    使用Swift在UITableViewCell中获取UITextField的indexPath

  16. 16

    如何从Swift中的indexPath获取UITableViewCell对象?

  17. 17

    使用Swift在UITableViewCell中获取UITextField的indexPath

  18. 18

    如何获取indexPath并在NSMutableArray中写入

  19. 19

    cellForItemAtIndexPath 获取块中 indexPath 的错误值

  20. 20

    iOS:UICollectionview,如何通过它的indexPath获取单元格的contentoffset

  21. 21

    如何在prepareForSegue中获取启动segue的按钮?

  22. 22

    如何在prepareForSegue中获取启动segue的按钮?

  23. 23

    在UITableView中获取核心数据对象的indexPath

  24. 24

    iOS 7-如何从放置在UITableViewCell中的按钮获取indexPath

  25. 25

    如何从tableView中获取索引号:cellForRowAtIndexPath:使用`indexPath`参数?

  26. 26

    获取嵌入在UITableViewCell中的UITable的单元格的indexPath

  27. 27

    在单元格中获取 indexPath.row

  28. 28

    prepareForSegue UICollectionView不起作用(快速)

  29. 29

    获取UICollectionView中Scroll的总高度?

热门标签

归档