带代码和集合视图的segue

时间:2015-08-29 13:32:53

标签: ios swift uicollectionview

如何使用代码和集合视图制作segue?

只是为了测试我点击时可以更改每个单元格的颜色。所以它选择好每个细胞:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {  
    if let cell = collectionView.cellForItemAtIndexPath(indexPath) {
    cell.backgroundColor = UIColor.redColor()
    } 
}

但是后来我没有改变颜色,只用代码制作了segue。相同的代码在表视图中工作,但它不具有集合视图。我错过了什么? (顺便说一下,我没有导航控制器)

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {  
    let detailController = self.storyboard!.instantiateViewControllerWithIdentifier("SecondlViewController") as! SecondViewController

    presentViewController(detailController, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:1)

你试过了吗?

performSegueWithIdentifier("Identifier", sender: self)