I have an issue trying to transfer a number (numText) in a textField. When I type a number it prints 0.
I know I have the number when I enter it because I can print it in my return function. What is the issue here?
Code Block func sendTypedNumToParent() { if anotherNum != nil { let data = numText anotherNum?.sendTyped(data: data) print("this is the typed number being transferred \(data)") } }
I know I have the number when I enter it because I can print it in my return function. What is the issue here?
Code Block func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() let text = textField.text let numText = originalNum if revNumber.text == text { revSlider.value = Float(numText) / 6.75675675676 revHeight.constant = CGFloat(revSlider.value) if numText < 316 { revLabel.text = "" } else { revLabel.text = "Revenue" } } print("I typed this \(numText)") sendTypedNumToParent() let name = Notification.Name(rawValue: typedCal) NotificationCenter.default.post(name: name, object: nil) return true }
I found my mistake I was trying to transfer numText instead of originalNum.
Code Block func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { // Make sure the user entered a number let num = Double(textField.text!) originalNum = Int(textField.text!)! if num! < 0 { textField.text = "0" } else if num! > 1000 { textField.text = "1000" } else if num! >= 0 || num! <= 1000 { textField.text = String(Int(num!)) } return true }
Code Block let numText = originalNum