I need the index of a cell of my UICollectionView
. I know how get it, but the problem is when I convert this NSIndexpath
to Int
. This is my code.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let cell = sender as! UICollectionViewCell
let index = self.collectionView!.indexPathForCell(cell)!
let vc : VideosViewController = segue.destinationViewController as! VideosViewController
vc.id_category = self.result_category[index.row as Int]["id"].intvalue
}
You don't need to convert the index.row
to Int
, it's a Int
already, see the declaration of Apple:
var row: Int { get }
In the class NSIndexPath
.
Just do vc.id_category = self.result_category[index.row]["id"].intvalue
. Just be careful with the index of out bound
in the array.
I hope this help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.