swiftuitextviewuitextviewdelegate

textViewDidBeginEditing on 2 separate textViews in swift


I have 2 separate textViews that I want to trigger an event when each of them are tapped. the termTextView triggers fine, but when termTextView is triggered first, the definitionTextView does not trigger when tapped. What can I do to fix this issue?

extension saveScreenViewController: UITextViewDelegate {
    func textFieldDidBeginEditing(_ textField: UITextField) {

    }
    func textViewDidBeginEditing(_ termTextView: UITextView){
        if(self.termTextView.text == "type term here..."){
        termTextView.text = ""
        termTextView.textColor = #colorLiteral(red: 0.1298420429, green: 0.1298461258, blue: 0.1298439503, alpha: 1)
        }
    }

    private func textViewDidBeginEditing2(_ definitionTextView: UITextView) {
        if(self.definitionTextView.text == "type definition here..."){
        definitionTextView.text = ""
        definitionTextView.textColor = #colorLiteral(red: 0.1298420429, green: 0.1298461258, blue: 0.1298439503, alpha: 1)
        }
    }
}

Solution

  • you need to change private func textViewDidBeginEditing2(_ definitionTextView: UITextView) to func textViewDidBeginEditing(_ definitionTextView: UITextView)