私はコレクションビューのセルに画像を持ち、その下にボタンがあります。このボタンをクリックすると、tableviewCell
を読み込み、コレクションビューの画像をロードします。これを達成するために、私は、だから私は再びcollectionviewでindexPathにアクセスする
let point = sender.convert(CGPoint.zero, to: self.collectionView)
let myIndexPath = self.collectionView.indexPathForItem(at: point)
self.photoThumbnail.image = self.arrayOfURLImages[(myIndexPath?.row)!]
。これを試してみました。しかしvar photoThumbnail: UIImageView!
... ..
func SellBtnTapped(_ sender: UIButton) {
let indexPath = collectionView?.indexPath(for: ((sender.superview?.superview) as! RecipeCollectionViewCell))
self.photoThumbnail.image = self.arrayOfURLImages[(indexPath?.row)!]
とphotoThumbnail
がそうのように定義された当初はこれをしなかった。しかし、これを行うことは'Unexpectedly found nil while unwrapping an optional value'
を伝えるクラッシュを与えますUnexpectedly found nil....
の同じクラッシュが起こっています。どのような問題になる可能性がどのようなアイデア..?
EDIT: これはなかれnil
あなたindexPathを得るためですcellForItemAtIndex...
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! RecipeCollectionViewCell
cell.sellButton.tag = indexPath.item
cell.sellButton.addTarget(self,action: #selector(SellBtnTapped(_:)),for: .touchUpInside)
return cell
}
にあなたの行動があなたのcollectionView(_ collectionView追加になります:。またエラーがで発生している行た説明UICollectionViewメソッドのコード – iPatel
を –
あなたはcellForItemAtを意味... @iPatel? – bws