[英]How convert NSIndexPath to Int in Swift?
我需要UICollectionView
的单元格的UICollectionView
。 我知道如何获得它,但是问题是当我将此NSIndexpath
转换为Int
。 这是我的代码。
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
}
您不需要将index.row
转换为Int
,它已经是一个Int
了,请参阅Apple的声明:
var row: Int { get }
在类NSIndexPath
。
只需执行vc.id_category = self.result_category[index.row]["id"].intvalue
。 只需注意数组index of out bound
。
希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.