O'Reilly logo

Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android by Michael Eierman, Jakob Iversen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dismissing the Keyboard

As you may have noticed, the keyboard doesn’t go away by itself when a text field loses focus. To get the keyboard to disappear, you have to add a little code to the program. What you need to do is change the View, which is the background of the app, so that it is able to respond to a tap. When the view intercepts a tap, it will then send a message to the text field to resign control. This makes the keyboard disappear. The first thing to do is set up the code to handle the event and then tie the event to the code.

In LMAViewController.h, add this line between the @interface line and the @end line to define a new action method:

- (IBAction)backgroundTap:(id)sender;

In LMAViewController.m, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required