我有一个 UICollectionView 动态加载单元格,但我想在推送单元格时打开一个不同的 UIViewController。
例如:
-cell1 打开 UIViewController1
-cell2 打开 UIViewController2
-cell3 打开 UIViewController3
有谁知道,如果有可能做到这一点?
最佳答案
您需要从包含 Collection View (不是单元格)的 View Controller 创建一个 segues 到目标 View Controller ,例如:
UICollectionViewController -> UIViewController1
UICollectionViewController -> UIViewController2
//...etc
请记住为每个 segue 添加标识符。
并在代码中覆盖
UICollectionViewDelegate
方法collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
在该方法中检查哪个单元格被点击(indexPath),如果是 cell1,则使用正确的标识符调用 segue:
performSegueWithIdentifier("goToVC1Identifier", sender: nil)
关于ios - 每个 UICollectionViewCell 的 UICollectionView 不同的 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30378855/