0
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
   if text == "\n" {
       tempDescription = txteditdescription.text
       txteditdescription.resignFirstResponder()
       return false
   }
   return true
}

i'm new in ios developement it is my string variable -> "tempDescription" i want store edited text in string variable on keyboard return key.

it is my textview -> "txteditdescription" but through above method my simulator keyboard not hide. so what i have to do ? Thanks

Vlad Pulichev
  • 3,162
  • 2
  • 20
  • 34
hardik
  • 199
  • 1
  • 6
  • 21

2 Answers2

0

Drag from your textfield to the viewcontroller it's connected to, and create an action event called 'Did End On Exit', and call it whatever you want.

enter image description here

Then inside of the function, call

self.resignFirstResponder()

like this

@IBAction func dismiss(_ sender: Any) {
    self.resignFirstResponder()
}
Tyler Rutt
  • 567
  • 2
  • 8
  • 24
0

You should assign the delegate like this.

txteditdescription.delegate = self

Then implement the delegate method shouldChangeTextInRange

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    if (text == "\n") {
        textView.resignFirstResponder()
        return false
    }
    return true
}
handiansom
  • 783
  • 11
  • 27