Showing posts with label Making the Keyboard disappear. Show all posts
Showing posts with label Making the Keyboard disappear. Show all posts

Saturday, July 10, 2010

Making the keyboard disappear - Easy Loan Calculator Part 4

How do we make the keyboard disappear?

Surprisingly, the return/done key does not allow us to close the keyboard.

What we aim to achieve to do here is whenever the user clicks outside of any textbox, the key board will disappear. How do we do that?

In Interface Builder, create a button and stretch it over the entire screen. It should cover the entire screen. Go to Layout -> Send to back. The button should be send to the back.



Hence, whenever a user clicks outside the textbox, she is actually clicking on the background button.

Remember that we have actually declared an Action in the .h file.

-(IBAction) bgTouched:(id) sender;


We have also implemented it in the .m file. 



-(IBAction) bgTouched:(id) sender{
[tbxLoanAmount resignFirstResponder];
[annualInterestRate resignFirstResponder];
[noOfYears resignFirstResponder];
}

What we are doing is resigning control of all the textboxes whenever the background button is clicked. This is done via calling the textbox resignFirstResponder instance method.

Last by not least, in Interface Builder, connect the background button to the bgTouched Action and your Easy Loan Calculator is finally complete! Yes after four parts!!

Press Command -R to try.

Feel free to give comments.