私はcollectionviewcellにuibuttonを追加する簡単なアプリを作ったが、私がアクションを与えるとエラーが発生する。ここにスクリーンショットがあります。CollectionViewCellのUIButton "IndexPathが機能しません"
クラスの私のコード:UIbuton {}
import Foundation
import UIKit
class KeypadUIButton: UIButton {
var qIndex : NSIndexPath?
}
と私のセルクラスがある:
でimport UIKit
class ConverterCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var keypadButton: KeypadUIButton!
}
とエラー:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = padCollectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! ConverterCollectionViewCell
let index = indexPath.row
// -> cell.keypadButton.qIndex = indexPath as NSIndexPath
return cell
}
私の間違いはどこですか?手伝って頂けますか ?
あなたの 'keypadButton'コンセントは接続されていません。 – rmaddy
あなたのstroyboardでは、ボタンクラスを 'KeypadUIButton'に設定しましたか? – Bilal