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.
Hi,
ReplyDeleteThank u very very much for this post,,,its really very helpful for me....
Actually I m very new to iPhone,,, and all the post related to "Easy Loan Calculator" help me a lot....
But 1 thing I am not getting i.e.from where I will get the option "Layout -> Send to back" ? I have search all IB option but not got....Please reply ASAP.
Thanks & Regards
Archana Chaurasia
But 1 thing I am not getting i.e.from where I will get the option "Layout -> Send to back" ? I have search all IB option but not got....Please reply ASAP.
ReplyDeleteThanks & Regards
Archana Chaurasia
please update me that from where I will get this option "Layout -> Send to back" to make key board disappear ?
ReplyDeleteI am not getting this option on IB even after the selection of button...
plz reply me ASAP..
Thanks & Regards
Archana Chaurasia
Hi Jason, great post and great web site! I do have a question regarding this post on hiding the keyboard by using a background button. When I turn the iphone/ipad to landscape view, the background button does not seem to orientate to landscape view such that I could see the outline of the button. Any idea on how to remedy this?
ReplyDelete