UITextField 的值更改和编辑更改事件之间有什么区别
what's the difference between the value changed and editing changed event of UITextField
我目前正在 swift 阅读一本关于设计模式的书,并且有一个程序可以在步进器的值更改或与其关联的文本字段更改时通知方法,这是方法
@IBAction func stockLevelDidChange(sender: AnyObject) {
println("Method Trigged")
if var currentCell = sender as? UIView {
while (true) {
currentCell = currentCell.superview!;
if let cell = currentCell as? ProductTableViewCell {
if let id = cell.productID? {
var newStockLevel:Int?;
if let stepper = sender as? UIStepper {
newStockLevel = Int(stepper.value);
} else if let textfield = sender as? UITextField {
if let newValue = textfield.text.toInt()? {
newStockLevel = newValue;
}
}
if let level = newStockLevel {
products[id].4 = level;
cell.stockStepper.value = Double(level);
cell.stockField.text = String(level);
}
}
break;
}
}
displayTotalStock();
}
}
但是我在更改此代码线程时遇到了一些问题,首先当我只是剥离 while 外观时,它就是不起作用。
@IBAction func stockLevelDidChange(sender: AnyObject) {
println("Method Trigged")
if var currentCell = sender as? UIView {
currentCell = currentCell.superview!;
if let cell = currentCell as? ProductTableViewCell {
if let id = cell.productID? {
var newStockLevel:Int?;
if let stepper = sender as? UIStepper {
newStockLevel = Int(stepper.value);
} else if let textfield = sender as? UITextField {
if let newValue = textfield.text.toInt()? {
newStockLevel = newValue;
}
}
if let level = newStockLevel {
products[id].4 = level;
cell.stockStepper.value = Double(level);
cell.stockField.text = String(level);
}
}
break;
}
displayTotalStock();
}
}
而且,当我将文本字段的事件从编辑更改更改为值更改时,它也不起作用!!!
谁知道那里发生了什么,谢谢
正在编辑更改文本字段状态。
Value Changed 是 textField 内容发生了变化。
如果你想做一些操作,你可以使用
这样的:
[textField addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventValueChanged];
您可以更改目标的控制事件。行动。
谢谢
来自苹果的UIControl Control Events docs:
UIControlEventValueChanged
A touch dragging or otherwise manipulating a control, causing it to emit a series of different values.
UIControlEventEditingChanged
A touch making an editing change in a UITextField object.
我目前正在 swift 阅读一本关于设计模式的书,并且有一个程序可以在步进器的值更改或与其关联的文本字段更改时通知方法,这是方法
@IBAction func stockLevelDidChange(sender: AnyObject) {
println("Method Trigged")
if var currentCell = sender as? UIView {
while (true) {
currentCell = currentCell.superview!;
if let cell = currentCell as? ProductTableViewCell {
if let id = cell.productID? {
var newStockLevel:Int?;
if let stepper = sender as? UIStepper {
newStockLevel = Int(stepper.value);
} else if let textfield = sender as? UITextField {
if let newValue = textfield.text.toInt()? {
newStockLevel = newValue;
}
}
if let level = newStockLevel {
products[id].4 = level;
cell.stockStepper.value = Double(level);
cell.stockField.text = String(level);
}
}
break;
}
}
displayTotalStock();
}
}
但是我在更改此代码线程时遇到了一些问题,首先当我只是剥离 while 外观时,它就是不起作用。
@IBAction func stockLevelDidChange(sender: AnyObject) {
println("Method Trigged")
if var currentCell = sender as? UIView {
currentCell = currentCell.superview!;
if let cell = currentCell as? ProductTableViewCell {
if let id = cell.productID? {
var newStockLevel:Int?;
if let stepper = sender as? UIStepper {
newStockLevel = Int(stepper.value);
} else if let textfield = sender as? UITextField {
if let newValue = textfield.text.toInt()? {
newStockLevel = newValue;
}
}
if let level = newStockLevel {
products[id].4 = level;
cell.stockStepper.value = Double(level);
cell.stockField.text = String(level);
}
}
break;
}
displayTotalStock();
}
}
而且,当我将文本字段的事件从编辑更改更改为值更改时,它也不起作用!!!
谁知道那里发生了什么,谢谢
正在编辑更改文本字段状态。 Value Changed 是 textField 内容发生了变化。
如果你想做一些操作,你可以使用
这样的:
[textField addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventValueChanged];
您可以更改目标的控制事件。行动。 谢谢
来自苹果的UIControl Control Events docs:
UIControlEventValueChanged
A touch dragging or otherwise manipulating a control, causing it to emit a series of different values.
UIControlEventEditingChanged
A touch making an editing change in a UITextField object.