I made a simple app add uibutton to collectionviewcell but when i give action an error occurs. Here is a screenshoot.
and my code of class: UIbuton {}
import Foundation
import UIKit
class KeypadUIButton: UIButton {
var qIndex : NSIndexPath?
}
and my cell class is :
import UIKit
class ConverterCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var keypadButton: KeypadUIButton!
}
and error in :
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
}
Where is my mistake. can you help me ?
Oh! I've got your error, it seems you missed this:
Type in your class name: KeypadUIButton
Also you don't need to use NSIndexPath in swift. Just use IndexPath instead. So you won't need to down cast it.