override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let selectedItem = collectionView?.indexPathForCell(sender as UICollectionViewCell) {
if segue.identifier == "next" {
var second: SecondViewController = segue.destinationViewController as SecondViewController
second.itemNumber = selectedItem.row
}
}
}
override func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {
if let cell = collectionView.cellForItemAtIndexPath(indexPath) {
performSegueWithIdentifier("next", sender: cell)
}
return true
}
override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
}
函数shouldSelectItemAtIndexPath
完全按照didDeselectItemAtIndexPath
的方式运行。 didDeselectItemAtIndexPath
以某种单元格而不是随机方式运行。那么这里的问题是什么?