What is the difference between a modified value and editing a modified UITextField event

I am currently reading a book on design patterns in swift, and there is a program that the method receives notification when the step value or the associated text field changes, here is the method

@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(); } } 

but I have some problems when changing this stream of code, firstly, when I just deleted the look, it just didn't work.

 @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(); } } 

and also, when I changed the text field event from the edit, changed to the changed value, it just doesn't work either.

who knows what's going on there, thanks

+5
source share
2 answers

Editing changes - textField statu. The changed value of the TextField is changed.

if you want to perform some operation you can use

Such:

 [textField addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventValueChanged]; 

You can change the control event for your purpose. Act. Thanks.

+5
source

Apple's UIControl Event Management Docs :

UIControlEventValueChanged
Dragging and dropping or otherwise manipulating a control, as a result of which it emits a number of different values.

UIControlEventEditingChanged
A touch makes an edit change in a UITextField object.

+1
source

All Articles