F
F
Felix Fimberg2020-08-26 13:05:10
Swift
Felix Fimberg, 2020-08-26 13:05:10

How to remove unrecognized selector sent to instance?

The application converts the temperature, there is a slider and 2 text fields. When moving the slider and changing Fahrenheit, everything works, but when changing the text in the Celsius field, the application crashes with unrecognized selector sent to instance

@IBAction func sliderMove(_ sender: UISlider) {
        
        let celTemp = Int(round(slider.value))
        textCel.text = "\(celTemp)"
        
        let farTemp = Int(round((slider.value * 9 / 5) + 32))
        textFar.text = "\(farTemp)"
        
    }
    
    @IBAction func textChangeFar(_ sender: UITextField) {
        
        guard let farTemp = textFar.text else { return }
        
        let farTempDouble = Double(farTemp)!
        let celsium = Int(round((farTempDouble - 32) * 5 / 9))
        textCel.text = "\(celsium)"
        slider.value = Float(celsium)
        
    }
    
    
    @IBAction func textChangeCel(_ sender: UITextField) {

        guard let celTemp = textCel.text else { return }
        
        let celTempDouble = Double(celTemp)!
        let farengeight = Int(round((celTempDouble * 9 / 5) + 32))
        textFar.text = "\(farengeight)"
        slider.value = Float(celTemp)!
        
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question