我试图使每个不同的单元格都能够被单击,并将它们带到新的视图控制器。
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell
let cellLabels = cell.viewWithTag(1) as! UILabel
cellLabels.text = arrayOfCellLabel[indexPath.row]
return cell
} // # Of Cells
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrayOfCellLabel.count
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 0 {
self.performSegueWithIdentifier("box", sender: self)
}
if indexPath.row == 1 {
self.performSegueWithIdentifier("box1", sender: self)
}
}
您需要使用集合视图委托而不是表视图的委托
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
switch (indexPath.row) {
case 0:
self.performSegueWithIdentifier("box", sender: self)
case 1:
self.performSegueWithIdentifier("box1", sender: self)
default:
break
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句