So, you’re developing an iOS app for the iPhone, iPod Touch or iPad.  Say you have a few textfields and nice little Round Rect button to submit the user’s input. Unfortunately, after the user enters the last field they don’t click “Done” on the keyboard.  In fact, they have the nerve to just click your submit button!  Sadly, your keyboard doesn’t go away because you haven’t programmed it to yet.  Yuck!  That’s ok, this is easy.  Inside the controller for your button add this (replace “yourTextField” with the name of your textfield)…

if ([yourTextField isFirstResponder]) {
    [yourTextField resignFirstResponder];
}

Have multiple fields?  No problem.

if ([yourTextField isFirstResponder]) {
    [yourTextField resignFirstResponder];
} else if ([anotherTextField isFirstResponder]) {
    [anotherTextField resignFirstResponder];
}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments