In the code below, fahrenheitFieldEditingChanged() is called as expected if it has the parameter
textField: UITextField
If I remove the parameter from the function, it doesn't seem to be called, even though I delete the connection from the old function prototype and recreate it for the new one. I know it isn't being called because I added this line at the beginning of the function, and the change doesn't happen no matter what I do:
celsiusLabel.text = "?????"
Please help? Here's my code. (And why do I care about the parameter? I was hoping I could just refer to my IBOutlet textField, which should be the same object as what would be passed to the edit change function, since my storyboard only has one UITextField in it.)
import Foundation
import UIKit
class ConversionViewController: UIViewController {
@IBOutlet var celsiusLabel: UILabel!
@IBOutlet var textField: UITextField!
var fahrenheitValue: Double? {
didSet {
updateCelsiusLabel()
}
}
var celsiusValue: Double? {
if let value = fahrenheitValue {
return (value - 32) * 5/9
}
else {
return nil
}
}
func updateCelsiusLabel() {
if let value = celsiusValue {
celsiusLabel.text = "\(value)"
}
else {
celsiusLabel.text = "???"
}
}
@IBAction func fahrenheitFieldEditingChanged() {
if let text = textField.text {
if let value = Double(text) {
fahrenheitValue = value
}
else {
fahrenheitValue = nil
}
}
}
@IBAction func dismissKeyboard(sender: AnyObject) {
textField.resignFirstResponder()
}
}
fahrenheitFieldEditingChanged
and see whether you hit it when you type in the field. If you do, it's being called. :)