[英]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.