Test App
Test App

Reputation: 103

Swift multiple UITexView resign responder handling

In my case, I am having two textview one I placed into view another one within UIAlertController. Here, I added done and cancel button on keyboard accessory with actions. Now, how to create resign responder for both UITextView?

@IBAction func doneClick(_ sender: Any) {
    self.descriptionTextView.resignFirstResponder()
    self.textView.resignFirstResponder() // Its making crash sometime 
}

Upvotes: 0

Views: 36

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100523

It appears that one of them is nil at some time , so You can do

self.view.endEditing(true)

Or make them optional like

self.descriptionTextView?.resignFirstResponder()
self.textView?.resignFirstResponder()

Upvotes: 1

Related Questions