私はCollectionViewとカスタムCellを持つTableViewControllerを持っていますが、そのCollectionViewからSegueをTableViewに準備する必要があります。Segue With UICollectionView
私はこの試みた:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "drawSegue" {
let dst = segue.destination as! DrawerViewController
guard let indexPath = cupCollectionView.indexPathsForSelectedItems else{
return
}
dst.cup = cupboards[indexPath.row] as! Cupboard
}
}
をしかし、私はエラーValue of type '[IndexPath]' has no member 'row'
を取得します。それを行う別の方法がありますか?私はのtableViewからのtableViewにこれを使用し、それが働いていた別のプロジェクトで原因...
これは私のCollectionViewです:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cupboards.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cupCell", for: indexPath) as! CupboardCollectionViewCell
let cupboard = cupboards[indexPath.row]
cell.cupLabel.text = cupboard.name
return cell
}
はcupCollectionView.indexPathsForSelectedItems
が戻っているように見え事前
に変更できます。これを 'let indexPath = cupCollectionView.indexPathに変更しました。 UICollectionViewCell) 'それは動作するように見えます、ありがとう:) – Sane