lundi 13 novembre 2017

Swift Error: unrecognized selector sent to instance

I have a custom checkbox that used to work in Xcode 8 is no longer working in Xcode 9. I'm getting the following error

'NSInvalidArgumentException', reason: '-[Project.CheckBox buttonClicked:]: unrecognized selector sent to instance.

The following is the custom class for the checkbox

 import UIKit

class CheckBox: UIButton {

//images
let checkedImage = UIImage(named: "checked_checkbox")
let unCheckedImage = UIImage(named: "unchecked_checkbox")

//bool propety
var isChecked:Bool = false{
    didSet{
        if isChecked == true{
            self.setImage(checkedImage, for: [])
        }else{
            self.setImage(unCheckedImage, for: [])
        }
    }
}


override func awakeFromNib() {
    self.addTarget(self, action: Selector(("buttonClicked:")), for: UIControlEvents.touchUpInside)  // I think this is the line that is generating the error.
    self.isChecked = false
}



func buttonClicked(sender:UIButton) {
    if(sender == self){
        if isChecked == true{
            isChecked = false
        }else{
            isChecked = true
        }
    }
}
 }  




Aucun commentaire:

Enregistrer un commentaire