【发布时间】:2016-08-31 02:29:22
【问题描述】:
我正在尝试创建一个变量“indexx”,它将被连接到我的下一个 tableController。 indexx 将保存我的 collectionView 中所选单元格的 indexPath,但是,我不确定要使用哪个属性。我对 tableController 属性非常熟悉,所以我很难为这段代码找到一个成功的解决方案。你会碰巧知道我的错误吗?
简要说明 - foodcv 是我的 collectionView,numberr 是第二个目标控制器中的变量。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destViewController = segue.destination as? foodtable {
let indexx = self.foodcv.indexPath(for: foodcell)
destViewController.numberr = indexx
}
}
let numberr : IndexPath = []
【问题讨论】:
-
是否有 indexpathforselecteditem - 单数形式?
-
@jonpeter 没有,但
allowsMultipleSelection=false保证collectionView.indexPathsForSelectedItems()返回 1 或 0 个元素,因此您可以检查如下:if let selectedPath = collectionView.indexPathsForSelectedItems().first { ...。
标签: swift xcode uicollectionview nsindexpath