I currently am trying to dismiss the keyboard from the previous text field when clicking a button. I currently have one method working to dismiss the keyboard, although it only dismisses it when the user taps away.
you can call this method every time you wanted to resign the
self.view.endEditing(true)
and you can dismiss keyboard from every textfield you wanted , you can call this method :
myTextField.resignFirstResponder()
Related
i want to show my keyboard on screen , whenever a view is shown i.e my login screen..
and i also want to change the name of enter button to Login button.
please help
To change the return key value, change the UIReturnKeyType enum (UITextInputTraits).
If you want the keyboard to show on the screen when it loads, you need to hook up your UITextField to the delegate and include UITextFieldDelegate in your header file. (That is assuming you are using a UITextField.)
Then call:
[textField becomeFirstResponder]
in your viewWillAppear method to give focus to the UITextField which then raises the keyboard.
When you click on a textfield in your iphone application, you will get the keyboard displayed. On that keyboard you will get a GO, DONE and SEARCH buttons. I need to get the On click event of these buttons.
What are they ?
become the delegate of the text field in question and you get sent
-(BOOL)textFieldShouldReturn:(UITextField *)textField
When the user taps the return button, whatever the label on the button is. (GO, SEARCH or DONE)
I have a UIAlertView with a text field in it. This view works correctly; it appears in the top half of the screen, so when the keyboard comes up, both buttons and the text entry are still visible and tappable.
However, if a local or remote notification from another application comes in while the text field is the first responder and the keyboard is up, it hides my alert and places the new alert behind the keyboard. If the alert is more than one line long, its buttons cannot be clicked and the user cannot dismiss it. It's not dismissing my alert view via any of the normal mechanisms - neither alertView:clickedButtonAtIndex: or alertView:cancel: get called on my delegate - but rather simply hides it temporarily using some unknown mechanism.
Can I get notified when a notification hides my alert view, so I can dismiss the keyboard and let the user deal with the notification? Are there any other events I can hook into to catch this case?
Register for the application’s UIApplicationWillResignActiveNotification; when you get that, dismiss your alert view. From the docs:
An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.
Alert views, such as those presented by notifications from other apps, are overlay windows. Watch for that notification, close your alert so the keyboard doesn’t get in the way, and be prepared to re-display the alert if your app then gets the UIApplicationDidBecomeActiveNotification.
I hope this will help...
- (void)willPresentAlertView:(UIAlertView *)alertView {
if (newAlertViewWhichBlocks.tag == alertView.tag) {
[yourTextField resignFirstResponder];
}
}
Do remember to set delegate of alert view.
I have a keyboard which edits text in a UITextView and tapping the return key doenst dismiss the keyboard, it only moves down to the next line.
How can I add a done button and make that dismiss the keyboard?
Implement the
textView:shouldChangeTextInRange
method to look for "\n" then call
resignFirstResponder on the textView if it is found.
Reference
The scope of this question is IPhone 3.1 sdk (app running in simulator still)
I have a table view that has a cell with a UITextField in that cell. The table view is grouped, and has one section with just a couple fields. Im NOT using IB so backgroundTap is out of the question (as far as i can tell at least). When i click the text field, keyboard shows. Hiding it is still troublesome. Ive pulled the UITextFieldDelegate into the mix to hide the keyboard but the textFieldShouldEndEditing method doesnt seem to fire when the background is tapped (when i mean background, im tapping outside of the grouped table view section). First off, should it?
textFieldShouldReturn fires with no problem and i can resign at this point but shouldnt i be able to resign if focus shifts away from that control?
Any help is much appreciated
-me
Generally you'll only stop editing a field when you:
hit the "Done" or action button on the keyboard
begin editing another field
exit the view
have another button on screen that removes focus
From any of these, you can call -[textField resignFirstResponder] to dismiss the keyboard and call your -textFieldShouldEndEditing: method. There's no reason that just tapping on a non-active part of the screen should dismiss the keyboard.