2017-11-27 1 views
0

私は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が戻っているように見え事前

答えて

2

にありがとうあなたがを呼び出すときに、あなたのdidSelectCell

存在しないので、代わりにあなたがArray<IndexPath>.rowを呼び出すようにしようとしている単一IndexPath.rowにアクセスするのIndexPathオブジェクトの配列、あなたのセルを送信者として追加してから、let indexPath = cupCollectionView.indexPath(for: sender)

+1

に変更できます。これを 'let indexPath = cupCollectionView.indexPathに変更しました。 UICollectionViewCell) 'それは動作するように見えます、ありがとう:) – Sane