iOS - Change a ViewController with the keyboard "next" button? - iphone

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.

Related

keeping iphone keyboard on screen and change its enter button name

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.

Custom UIKeyboard

Will really appreciate this if you can help me.Want to create a custom Keyboard that is compatible from iOS 3.0 and onwards.When click on the UITextField want to show my own keyboard.UItextfield inputView is being called on iOS > 3.0.
I have made a custom keyboard in my app. I created it in interface builder and made some class files for it. In the class files I created a protocol to call some delegate methods when the user presses on different buttons of the keyboard. In your view that you want to have your keyboard, just add a UITextField that is of location and size (0,0,0,0). The textfield will only serve as a mechanism to bring up your keyboard. Then in viewDidLoad or at an appropriate time you can set your UITextFields input view like this:
self.myTextField.inputView = self.myKeyboard.view;
Don't forget to set yourself as the delegate of your own keyboard.
self.myKeyboard.delegate = self;
Then when the user does something which warrants bringing up the keyboard, just call becomeFirstResponder on your keyboard. The key is to do it on the textField. Since your keyboard is the input view, it will come up instead.
[self.myTextField becomeFirstResponder];
When you want to dismiss it just resign it.
[self.myTextField resignFirstResponder];
and any buttons that your user clicks on on your keyboard should be handled by delegation.
Good luck to you.

does a modalviewcontroller resignFirstResponder of the parentviews subviews?

in order to recognize if a user jumps from editing one textField to another by just touching another one instead of hitting the return button i implemented a method which gets called with the event "Editing did end".
i read this event also happens when, in this case a textField resignsFirstResponder.
Now whenever the user hase a multiple choice I present a modal View with a picker.
I have the problem whenever there is a multiple choice and the user switches textFields without hitting return this method gets called twice and I don know why!
is it possible that the modalviewcontroller resigns all FirstResponder of the parentView when it gets presented ?
you can say
[myTextField1 resignFirstResponder];
[myTextField2 resignFirstResponder];
[myTextField3 resignFirstResponder];
before presenting your controller.
but i have a feeling there could be a better way to solve this if i can understand your problem clearly.

iPhone: how can I activate a text field programmatically (and not wait for the user to touch it)

I have a UIViewController that is a UITextFieldDelegate, and I would like the keyboard for its text field to appear as soon as the user navigates to this view, without having to actually touch the text field. It would also be nice to be able to "dismiss" the entire view when the keyboard is dismissed. I am loading the view from a xib file.
I don't have an ivar in the code for the UITextField as yet. I would guess I need one. At this point I am just relying on the delegate to pop up the keyboard.
(I know its not a UITextViewDelegate, like the tag says, but I am new to stackoverflow and can't create the correct UITextFieldDelegate tag.)
Sounds like you want to use [textField becomeFirstResponder] in viewDidAppear.

UITextFieldDelegate != IBAction backgroundTap

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.