Ios 如何在Swift中将nsindepath转换为Int?
我需要我的Ios 如何在Swift中将nsindepath转换为Int?,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我需要我的UICollectionView的单元格索引。我知道如何获得它,但问题是当我将此nsindepath转换为Int时。这是我的密码 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let cell = sender as! UICollectionViewCell let index = self.collectionView!.indexPathForCell(
UICollectionView
的单元格索引。我知道如何获得它,但问题是当我将此nsindepath
转换为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 }
在类nsindepath
中
只需执行vc.id\u category=self.result\u category[index.row][“id”].intvalue。只需小心数组中out bound的索引
我希望这对您有所帮助。当用户选择一个单元格时,您是否正在启动该序列?