【问题标题】:what is the collectionView form of indexPathForSelectedRow?indexPathForSelectedRow 的collectionView 形式是什么?
【发布时间】: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 = []

【问题讨论】:

标签: swift xcode uicollectionview nsindexpath


【解决方案1】:

也许为时已晚,但你去吧:

斯威夫特 4

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let destViewController = segue.destination as? foodtable {
        let indexPaths : NSArray = foodcv.indexPathsForSelectedItems! as NSArray
        let indexx : IndexPath = indexPaths[0] as! IndexPath
        destViewController.numberr = indexx[selectedindexPath.row]
    }
} 

【讨论】:

    【解决方案2】:

    使用这个修改后的实现,

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let destViewController = segue.destination as? foodtable {
            let indexx = self.foodcv.indexPathForCell(sender as! UICollectionViewCell)
            destViewController.numberr = indexx
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-26
      相关资源
      最近更新 更多