Want to hide keyboard with the press of a button in iOS - iphone

I've got an app with user input to enter some numbers and instead of having to push the done key on the keyboard to hide it I'd like for the keyboard to go away when they press the calculate button but I have not been able to figure out how to do this. Some hints please?
Thanks

In iOS you need to "resign" from being first responder in order for the keyboard to be removed from the screen. Simply call resignFirstResponder on your textfield:
[_yourTextFieldWithNumbers resignFirstResponder];

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/resignFirstResponder

Related

Prevent keyboard from resigning after "return" was triggered?

my question is kind of straightforward and pretty much the opposite of what most people try to achieve:
How can I prevent the keyboard from disappearing when the 'return' / 'done' button is pressed?
Thanks a lot!
Regards,
wasabi
You need to create a UITextFieldDelegate, and override the textfieldShouldReturn: method. If you return NO from this method, the keyboard will not disappear.
And of course, link up your delegate to the textField

how to popup default iphone keyboard on a button click

Hi
When we click on a UITextField or UITextView, a default keyboard pops up from the bottom of iphone screen. I want iphone keyboard to appear on a button click, and then handle the keys as typed on keyboard... How can i do that?
Add touchupinside event on button and call becomeFirstResponder method for textview or textfield it will call pop up keyboard.
see the following code-
-(IBAction)buttonClicktoModalView:(id)sender{
[textView becomeFirstResponder];
}
I was searching my problem, and came across the following stackoverflow link which answers my question
How to pull up a UIKeyboard without a UITextField or UITextView?
Thank you
Pls go through this
iphone keyboard without textview
Hope this helps

UITextView with "Done" button *and* "Return" key?

I use a UITextView for multiline text entry in my iPhone app, and I have set the "Return" key to display "Done." I've also set up the return key to disable first responder status, so that hitting "done" actually exits the UITextView. However, I also want to enable users to be able to enter multiline text into the UITextView, i.e. to be able to use the "Return" key. Is there any way to make this work on the iPhone/iPad's UI?
I've been struggling with this issue for 5 years waiting for apple to wake up and create some sort of solution for the textfield multiline responding to done button until I decided to create one myself.
there you go:UITextField multiline with hide keyboard option
It'll be time consuming but you could create your own keyboard with both these keys (this can be done by specifiying the Input View for the UITextView ).
Another alternative could be having a button that sits just above the keyboard that would dismiss the keyboard. You can use the UITextView's Input Accessory View which allows you to create a view that sits on top of the keyboard. See here for more information (I'm aware this document is for iPad but it works for all iOS devices - also just to note, both these require iOS 3.2 or greater).
This should only need to be done on the iphone because the iPad keyboard already comes with a dismiss keyboard button as well as a return button.

How do you launch a UITextView (iPhone) in edit mode?

I'm working on an iPhone app with only one view, a UITextView, and I want it to launch all ready for typing (with the keyboard activated) but by default it requires the user to first tap the view before the keyboard appears. I've seen this done in other applications but haven't been able to figure it out. Thanks.
you need to use the -becomeFirstResponder method on your field:
[myTextField becomeFirstResponder];
This will pop the keyboard up. To hide the keyboard, use -resignFirstResponder.

TextField with Keyboard in cocos2d !

I am trying to develop a iphone app by using cocos2d. I create a alert view with a text field. when I touch the text field then comes the keyboard. But I want that when the alert is open, in the same time textfield will be selected and keyboard comes(without any touch). how can it posible ? sorry for my bad English.
[myTextField becomeFirstResponder] will probably do what you want.
That would be a little tricky to do. The controls in iPhone use the concept of "first responders" Any events will be handled by the first responder in the controller. Now, when an alert view is displayed, it becomes the first responder so it can respond to button clicks. When a text field is selected by the user, the keyboard gets the control. So I guess what you want to achieve can be done by making the text field the first responder after showing the alert ([txtField becomeFirstResponder])
But I have no idea how the alert view's responses will be handled then. You won't be able to click the OK button on the alert view till the keyboard is dismissed and you resign the first responder of the text field. ([txtField resignFirstResponder]) (This is just a guess, you will have to check the final behavior)
[myTextField becomeFirstResponder] works -- I tested it.