Peter Boesen Peter Boesen - 1 year ago 171
iOS Question

resign first responder UITextfield

I am so sorry to post this, since it has been asked a million of times, but whenever i try to use one of the solutions, it is either outdated, or won't work with my code. (or maybe i am just doing it wrong)

i have 5 textfields and a textview, that go into an email, and i am trying to minimise the keyboard when im done, but i dont know how to.
I also tried to make it go to the next text field, until the last one, but that doesn't need to be done.

Im very new btw. so plz be very specific :D


func textView(textView: UITextView, shouldChangeTextInRange: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
return false
return true
func textFieldShouldReturn(textField: UITextField) -> Bool {

if textField == self.text1 {
else if textField == self.text2 {
else if textField == self.text3 {

else if textField == self.text4 {

return true;

Answer Source

first you have to add UITextFieldDelegate in .h

then in .m

yourtextfield.delegate = self

then apply this code

func textFieldShouldReturn(textField: UITextField!) -> Bool 
        return true;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download