【发布时间】:2014-11-20 22:41:14
【问题描述】:
当两个不同的文本字段的 EditingChanged 时,我有两个 IBAction。在这些方法中,我有一个 if 语句,如果两个 UITextField 都包含整数,则启用一个按钮。问题是,当按钮启用时,它保持启用状态,即使我编辑文本字段并更改它们,使它们除了整数之外还有字符。我该如何解决?提供代码时请彻底清晰,因为我是编程新手。如果您想知道,这是我目前拥有的代码:
@IBAction func calorieNumberEditingChanged(sender: AnyObject) {
// If both variables are true and the text fields contain integers, enable button
if self.yourWeightFilled && self.calorieNumberFilled {
self.calculateButton.enabled = true
}
}
@IBAction func yourWeightEditingChanged(sender: AnyObject) {
// If both variables are true and the text fields contain integers, enable button
if self.yourWeightFilled && self.calorieNumberFilled {
self.calculateButton.enabled = true
}
}
【问题讨论】:
标签: ios if-statement swift uibutton edit