我创建了一个带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
}
}
答案 0 :(得分:0)
为什么不简单地在您的didSet
方法中添加用于更改用户界面的代码?