Recipe: Dismissing a UITextField Keyboard
A commonly asked question about smaller devices and the UITextField
control is “How do I dismiss the keyboard after the user finishes typing?” There’s no built-in way to automatically detect that a user has stopped typing and then respond. Yet when users finish editing the contents of a UITextField
, the keyboard really should go away. The iPad offers a keyboard-dismissal button, but the iPhone and iPod touch do not.
Fortunately, it takes little work to respond to the end of text field edits, regardless of platform. You do so by allowing users to tap Done and then resign first responder status. Resigning first responder moves the keyboard out of sight, as Recipe 6-1 shows. Here are a few key points about ...
Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.