UITextField becomeFirstResponder but the keyboard doesn't showed - iphone

I create a uitextfield and explicitly I call:
[myTextField setEnabled:YES];
[myTextField becomeFirstResponder];
but the keyboard isn't showed. Can I explicitly call the keyboard?
Thanks

have you checked if your textfield is properly initialized ? Or is it for some reason nil.
or you did not connect it properly in IB ?
Maybe you can provide more information ?

this is possible if the user has an external keyboard enabled. You CANNOT explicitly call the keyboard

Related

resignFirstResponder does not dismiss keyboard

I have a UITextField and a UIButton. If the button is tapped while the text field is active, I want to dismiss the keyboard, but I'm unable to do so. I tried calling [textField resignFirstResponder] and [textField endEditing:YES] when the button is tapped, but they have no effect -- [textField isFirstResponder] returns false, so it's not surprising that resignFirstResponder has no effect. But in that case, why isn't the keyboard disappearing? Thanks.
Make sure your "textField" class member is properly hooked up in the nib file. NSLog it's value right before you call firstResponder and see if it's nil. Also, enter text into the textfield and see that you can properly print it out with NSLog at the same point you're calling resignFirstResponder. Usually when a control does not respond correctly it's because IBOutlets aren't hooked up properly.
Try making an IBAction
-(IBAction)textFieldReturn:(id)sender
{
[sender resignFirstResponder];
}
And connect it to the UIButton
have you added <UITextFieldDelegate> in your .H ??

resignFirstResponder and close keyboard from anywhere?

I have a situation where the keyboard maybe open and then an NSTimer pops a view over the text view. Is there anyway to close the keyboard globally rather than from the text view resignFirstResponder method? The reason I ask is that the textView is dynamic in that it maybe there sometimes and not others. One way would be to give it a TAG. Can multiple items be referenced with same tag?
I think the answer is no but I would be interested in your thoughts?
Thanks
Steve
To dismiss the keyboard from anywhere, even if you don't know directly who is the firstResponder, use:
[[[[UIApplication sharedApplication] delegate] window] endEditing:YES];
The endEditing: method of UIView should do the trick. Send it to the superview of the potentially existing UITextView when you want to dismiss the keyboard.
You can try to send some control the message becomeFirstResponder
You could pass a reference to the UITextView in the NSTimer...
ORRRRR....
In the view that pops up you could do something like:
for(id view in self.superview.subviews){
[(UIView *)view resignFirstResponder];
}

iPhone SDK: resignFirstResponder not working

For some reason, resignFirstResponder is not working. I am not sure why? I have tried to call it from textFieldDidEndEditing and nothing happens. A NIB is being used and each's delegate is pointing to files owner.
What needs to be done to get the keyboard to dismiss?
Thanks.
Don't use -textFieldDidEndEditing. That's called after the text field resigns firstResponder status, which is what you're trying to use it as a hook to make happen. Cart before horse, chicken-and-egg kind of problem.
Instead use -textFieldShouldReturn to get triggered when the return key is pressed (and remember to return YES; from that.) Also float a clear custom button behind the elements of the view and handle a "background tap" that goes through all the text fields on your view and resigns first responder on the lot of them.
actually you should return NO so that the text field does not begin editing at all. If it does, the firstresponder gets set and the keyboard pops up again.
Make sure your setting your delegates for the textfield.
myTextField.delegTe = self;
And you are using in your header:
<UITextFieldDelegate>
EDIT:
Try:
if(textField == myTextField){
[textField resignFirstResponder];
}

hiding the keypad on iphone

I have a form that looks like the following (see image). If the user hits the Login button, I want the keypad to disappear. How do I do that.
Note that TextFieldDelegate methods wouldnt get called since the user is simply hitting the UIButton (Login). Hence, anything I can put in the IBAction for this button?
Normally the keyboard should be dismissed automatically when the user taps somewhere outside of the textfield, but you can also manually hide it using
[textField resignFirstResponder]
set delegate for your text field <UITextFieldDelegate>
and over ride this method
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

Handle Keyboard Done pressed event on Iphone

I am moving my view when a text field is pressed in order to get proper view when keyboard appears. Now, when the Done keyboard button is pressed, I would like to return the view to its initial state. How do I handle an action when the done keyboard button is pressed?
The proper way to do this is to observe to the notifications UIKeyboardDidShowNotification and UIKeyboardDidHideNotification as detailed in Apple's documentation.
If you want to know when the Done button has been pressed, implement
- (BOOL)textFieldShouldReturn:(UITextField *)textField
In your delegate. It should be called when the return button is pressed. See API documentation for more details.
Make an IBAction and connect it to the text field's didEndOnExit method. Then within the implementation of this method you should put [yourTextFieldOutlet resignFirstResponder];, which will deactivate the text field.
#freespace has it right, this is all you need to do.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
return [textField resignFirstResponder];
}
Tap the done button and poof, the keyboard is gone.
If you just want to know that Done was pressed, you can ask to be told of that control event:
[textField addTarget:self
action:#selector(donePressed)
forControlEvents:UIControlEventEditingDidEndOnExit];
That's the code version of IB's didEndOnExit.