Skip to main content
edited title
Link
Iulian Onofrei
  • 9.9k
  • 11
  • 73
  • 118

dismiss keyboard with a uiTextViewUITextView

deleted 3 characters in body
Source Link
swiftBoy
  • 35.8k
  • 26
  • 140
  • 137

I am sure this is not that difficult, but I am having trouble finding info on how to dismiss a keyboard with the return/done key using a textview, not a textfield...here here is what I have tried so far(which works with a textfield...)

Thanks very much in advance for any help!

// PostTravelQuestion.swift import UIKit class PostTravelQuestion: UIViewController, UITextViewDelegate {     @IBAction func closepostpage(sender: AnyObject) { dismissViewControllerAnimated(true, completion: nil) } @IBOutlet var postquestion: UITextView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. postquestion.delegate = self } self addDoneToolBarToKeyboard:self.textView /*func textViewShouldEndEditing(textView: UITextView) -> Bool { textView.resignFirstResponder() return true }*/ /*override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { postquestion.resignFirstResponder() self.view.endEditing(true) }*/ override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func textViewShouldReturn(textView: UITextView!) -> Bool { self.view.endEditing(true); return true; } } 

I am sure this is not that difficult, but I am having trouble finding info on how to dismiss a keyboard with the return/done key using a textview, not a textfield...here is what I have tried so far(which works with a textfield...)

Thanks very much in advance for any help!

// PostTravelQuestion.swift import UIKit class PostTravelQuestion: UIViewController, UITextViewDelegate {     @IBAction func closepostpage(sender: AnyObject) { dismissViewControllerAnimated(true, completion: nil) } @IBOutlet var postquestion: UITextView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. postquestion.delegate = self } self addDoneToolBarToKeyboard:self.textView /*func textViewShouldEndEditing(textView: UITextView) -> Bool { textView.resignFirstResponder() return true }*/ /*override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { postquestion.resignFirstResponder() self.view.endEditing(true) }*/ override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func textViewShouldReturn(textView: UITextView!) -> Bool { self.view.endEditing(true); return true; } } 

I am sure this is not that difficult, but I am having trouble finding info on how to dismiss a keyboard with the return/done key using a textview, not a textfield. here is what I have tried so far(which works with a textfield.)

Thanks very much in advance for any help!

// PostTravelQuestion.swift class PostTravelQuestion: UIViewController, UITextViewDelegate { @IBAction func closepostpage(sender: AnyObject) { dismissViewControllerAnimated(true, completion: nil) } @IBOutlet var postquestion: UITextView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. postquestion.delegate = self } self addDoneToolBarToKeyboard:self.textView /*func textViewShouldEndEditing(textView: UITextView) -> Bool { textView.resignFirstResponder() return true }*/ /*override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { postquestion.resignFirstResponder() self.view.endEditing(true) }*/ override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func textViewShouldReturn(textView: UITextView!) -> Bool { self.view.endEditing(true); return true; } } 
Source Link
user3708224
  • 1.3k
  • 4
  • 20
  • 39

dismiss keyboard with a uiTextView

I am sure this is not that difficult, but I am having trouble finding info on how to dismiss a keyboard with the return/done key using a textview, not a textfield...here is what I have tried so far(which works with a textfield...)

Thanks very much in advance for any help!

// PostTravelQuestion.swift import UIKit class PostTravelQuestion: UIViewController, UITextViewDelegate { @IBAction func closepostpage(sender: AnyObject) { dismissViewControllerAnimated(true, completion: nil) } @IBOutlet var postquestion: UITextView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. postquestion.delegate = self } self addDoneToolBarToKeyboard:self.textView /*func textViewShouldEndEditing(textView: UITextView) -> Bool { textView.resignFirstResponder() return true }*/ /*override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { postquestion.resignFirstResponder() self.view.endEditing(true) }*/ override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func textViewShouldReturn(textView: UITextView!) -> Bool { self.view.endEditing(true); return true; } }