在iOS中调用其自己的类之前的其他类函数

时间:2015-04-24 14:28:59

标签: ios xcode swift checkbox

我创建了一个带class CheckBox的复选框按钮。我想根据ResultTextField的值启用/禁用checkbox ischecked。所以我将一个按钮与@IBAction func retestRequestedCheckbox_onChange()相关联。问题是func retestRequestedCheckbox_onChange()在更新CheckBox类中的值之前被调用。如何在调用retestRequestedCheckbox_onChange()函数之前更新复选框值?这是我的代码:

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    
        }

}

1 个答案:

答案 0 :(得分:0)

为什么不简单地在您的didSet方法中添加用于更改用户界面的代码?