iOS Hide Keyboard Method

Programming in iOS is fun, but it is sometimes difficult to find the simple things.  I have decided to document these "little things" when I come across them to share with others.  I am also a believer in writing posts that are great references for its author as well.

Last week, I learned a nice tidbit from Jose Mojica on how to hide your iOS keyboard when you click outside of your text box or any object that doesn't have a keyboard associated.  It uses resignFirstRepsonder on the touchesBegan method as shown below.

The method is running whenever there is a touch on the screen.  If the UITouch object is not empty then we will close the keyboard for our txtInput object; which is an object created for a textbox in the xib.  It is very simple, but not very apparent.  Enjoy.

]]>

Comments are closed.