I have an accessory view on my keyboard that uses a next and previous button to hop between UITextFields. When the next or previous button is pressed, an IBAction is called which finds the textfield to switch to and then performs
[nextTextField becomeFirstResponder];
Usually this works fine but once in a while the keyboard drops partially and then comes back up. I'm sure this is because becoming first responder dismisses the keyboard and then summons it back up again, and sometimes this happens slowly enough that the keyboard has visually begun dismissing before it is called back.
So how can I stop the keyboard from trying to dismiss?
The keyboard should only dismiss if you've explicitly called for it to dismiss (when you're in the same view). Just ensure there aren't any subsequent calls to:
[textField resignFirstResponder];
Another option is to conform to the UITextFieldDelegate protocol and implement these methods:
-(void)textViewDidBeginEditing:(UITextView *)textView
-(void)textViewDidEndEditing:(UITextView *)textView
The latter is where you'll want to NOT call your keyboard resigner
Related
iPhone app.
I have a simple view with UITextView as first responder. I resign first responder and pop to the previous controller but the keyboard stays. Textview doesn't even exist anymore but the keyboard is still visible.
The controller that I pop to is a tableview, no objects that can even assume first responder status. So the keyboard is just there obscuring half my table and there is not even a way to dismiss it. I have to navigate back to a view that has a text box or textview, select one and dismiss that in order to get rid of the keyboard.
How is this possible?
On viewWillAppear just write
[self.view endEditing:YES];
I'm trying to resign the keyboard when user clicks a UIButton, which triggers a new content view (of type UIViewController).
This 'compute' button is at the end of list of several textfield inputs which the user scrolls through for entry; there's no need to resign the keyboard in this view. The scrollview also accommodates resizing when the keyboard is activated.
However, I notice that when proceeding to the next view, upon button click, and then returning to this view of textfields, via the back button on the navigationbar, the keyboard remained up, and this view no longer scrolls the additional area occupied by the keyboard.
My idea is to dismiss the keyboard when the view changes, so when the view returns, any input will trigger keyboard notification and adjust the scroll view accordingly (which is working).
Thank you so much,
Something like this might get you going in the right direction:
- (void)viewWillDisappear:(BOOL)animated {
/* Dismisses the keyboard whenever the view disappears
*/
[self.view endEditing:YES];
[super viewWillDisappear:animated];
}
You could also put that endEditing call in the action handler for the "compute" button you mention.
Edit:Ok, this is weird... After doing extensive debugging, I have discovered that whilst the text fields are resigning first responder status (I can see that there is no longer a blinking bar in any), the keyboard is NOT GOING DOWN! Maybe this deserves a different question.
I have several text fields in a custom uiviewcontroller subclass, which is displayed within a popover. The popover is displayed form a bar button. I want the keyboard to go down when the popover is dismissed (either by the user tapping the bar button again, or tapping outside the popover. From the view controller that displays the popover, when the popover is dismissed, in either of the 2 fashions, I call
[optionsController dismissFirstResponder];
Optionscontroller is the uiviewcontroller subclass in the popover. Dismissfirstresponder is a method I defined:
-(void)dsimissFirstResponder {
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];
}
Those are three IBoutlets which I connected in the xib to the text fields.
That doesn't work. Any help with this would be greatly appreciated.
The code is called as such:
[optionsController dismissFirstResponder];
[poppoverController dismissPopoverAnimated];
I set a breakpoint in dismissFirstResponder and it is called when I expected it to be. I also checked, and all three IBOutlets are non-nil during that function call. These are the only text fields in the whole app, so I'm not sure how else to put the keyboard down.
What you need is to receive the delegate method callbacks for a popover. Have you looked at the docs for the UIPopoverControllerDelegate? The following methods are defined:
-popoverControllerShouldDismissPopover:
-popoverControllerDidDismissPopover:
These should get called when your user does any gesture to dismiss the popover (tapping outside, etc.) assuming you've set a delegate for your popover and you've implemented this formal protocol in that delegate. When – popoverControllerDidDismissPopover: gets called, you can just call -resignFirstResponder on your controls at that point.
// In your popover delegate
- (void)popoverControllerDidDismissPopover:
(UIPopoverController *)popoverController
{
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];
}
I recently discovered that if a UITextField is being edited in a controller that's attached to a UINavigationController and the back button is pressed, upon returning to this controller, the DidBeginEditing function is called again and the UITextField keyboard is brought back up. I was wondering if there's a way to stop the keyboard from coming back up. Maybe there's a way to hook the back button so it doesn't save the fact that the text field is being edited.
Implement viewWillDisappear: on the view controller that controls the text field, and call:
[theTextField resignFirstResponder];
This will dismiss the keyboard.
I have a UIViewController with 4 UITextFields, 3 of them use the NumberPad and 1 uses an ASCII keyboard. I can't get the ASCII keyboard to dismiss when the user touches a background button outside the text field. The background button works fine to dismiss the NumberPads but doesn't dismiss the ASCII keyboard.
Yes, the ASCII keyboard does have a Done button and that works (I have the delegate set in IB and have implemented textFieldShouldReturn) but I want all the fields to be able to dismiss by touching the background area so they behave consistently (as much as possible).
The background button's action method (below) is called and it does call resignFirstResponder for all my text field objects but the call for the textfield with the ASCII keyboard doesn't dismiss the keyboard, while the other calls for the numeric textfields do dismiss their NumberPads.
-(IBAction)backgroundClick:(id)sender
{
// resignFirstResponder makes the keyboard go away when the
// user clicks outside of one of the text fields
[textField resignFirstResponder];
[num1Field resignFirstResponder];
[num2Field resignFirstResponder];
[num3Field resignFirstResponder];
[num4Field resignFirstResponder];
}
What am I missing here?
Found the problem. The textField's Referencing Outlet was not connected to File's Owner in IB.
I thought I had checked the connections but obviously missed this.