I created a checkbox button with class CheckBox. I want to enable/disable ResultTextField according to the value of checkbox ischecked. So i linked a button with @IBAction func retestRequestedCheckbox_onChange(). The proble is the func retestRequestedCheckbox_onChange() is getting called before it updated value in CheckBox class. How can i update the checkbox value before calling retestRequestedCheckbox_onChange() function. Here is my code:
class Checkbox: UIButton {
let checkedImage = UIImage(named: "checked_checkBox") as UIImage?
let unCheckedImage = UIImage(named: "unchecked_checkBox") as UIImage?
var isChecked:Bool = false{
didSet
{
if isChecked == true{
self.setImage(checkedImage, forState: .Normal)
}else {
self.setImage(unCheckedImage, forState: .Normal)
}
}
}
override func awakeFromNib() {
self.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
self.isChecked = false
}
func buttonClicked(sender: UIButton){
if(sender == self){
if isChecked == true {
isChecked = false
} else {
isChecked = true
}
}
}
}
@IBAction func Checkbox_onChange(){
if CheckboxButton.isChecked ?? false {
ResultTextField.enabled = true
} else {
ResultTextField = false
}
}
Aucun commentaire:
Enregistrer un commentaire