创建多个segue使用CollectionView

时间:2017-04-13 23:28:09

标签: swift xcode

如下图所示,我有一个CollectionViewCell,并希望为TableViewController和ViewController创建多个segue。

如何创建多个segue?

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

要为TableViewController和ViewController创建多个segue,您需要从视图控制器创建一个segues,它将集合视图(不是单元格)保存到目标视图控制器,例如:

UICollectionViewController -> UIViewController1
UICollectionViewController -> UIViewController2
//...etc

请记住为每个segues添加标识符。

在代码覆盖UICollectionViewDelegate方法

collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)

在该方法中检查哪个单元被轻击(indexPath),如果是cell1,则使用正确的标识符调用segue:

performSegueWithIdentifier("goToVC1Identifier", sender: nil)
相关问题