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
Related
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()
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.
I've noticed it's possible to trigger actions and to move through text fields using the done/next/return key in the bottom right of the iOS keyboard. Would it be possible to maybe change a view or trigger a segue with that button?
For example, it would be cool to be able to type something into a UITextField, and then just tap "Next" to move onto the next viewController instead of having to use a separate button, or navigation item.
May be a stupid question, but something that I've been wondering if it was possible for a while.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//Next button was pressed
//Push some viewcontroller here
return YES;
}
make sure you set the delegate of the UITextField to self
It is possible. If it's a UITextField, you can implement textFieldShouldReturn:. If it's a UITextView, you implement textView:shouldChangeTextInRange:replacementText:, and look for \n in the replacement text.
In either case, you can then perform a segue, do a navigation or modal push, etc.
My problem is thus: I've created a custom view, a numeric keypad, that I display when a button is pressed. When anywhere else on the screen is tapped, I want to hide the keypad.
I solved the problem by overriding touchesBegan:withEvent. Then a hit test tells me if the numeric keypad was pressed. As long as the keypad wasn't pressed, I hide it (by setting its hidden property to YES).
It works, but I don't like it. Its not very clean. My other option is to have a view controller for the numeric keypad and display it as a modal view controller. The keypad view would have a transparent background. I don't like this method either.
Any ideas?
A simple solution would be to have an invisible UIButton that you add to the view when the keypad comes up and remove along with the keypad when it is tapped.
Of course, the tap you get on the UIButton will prevent you from using that tap for anything else, so your interface wouldn't work while the keypad is there.
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.