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
source share