Im passing data from one CollectionViewController
to a detail ViewController
. Everything seems to be working, but the "prepareForSegue
is happening before the "didSelectItemAtIndexPath"
so it's passing the data of the item I selected the last time not the one I'm selecting right now.
This is my wrong code for the collectionViewController
var cellSelected : Int = 0
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
cellSelected = indexPath.row
println("Did select!")
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "identifierName" {
var secondScene = segue.destinationViewController as detailVC
secondScene.authorDetail = data[cellSelected].userOfImg
secondScene.likesDetail = data[cellSelected].likesInImg
secondScene.imageDetail = data[cellSelected].imgPath
println("Prepare for segue")
}
}
The result in the debug area is:
- Prepare for segue
- Did select!