iOS - Automatically Have Keyboard Toggled On ViewController - ios

I have a view in my app where the user has to enter information in a textfield. Instead of them clicking into the text field and toggling the keyboard, I would like to have the textfield already editable with the keyboard preloaded there so the user can immediately start typing. Surprisingly, I couldn't find any resources that preload the keyboard when a view controller is reached.
Any help or advice would be appreciated. Thanks.

in the ViewDidAppear:
[yourTextField becomeFirstResponder];

Related

How to dismiss already opened keyboard when popover appears by other textfield ios

In my iOS project, I have a form which contains various text fields. Some text fields are edited by keyboard and some by picker view which is placed on the popover.
When I go on filling text fields, without dismissing it and then if I click on popover text field keyboard remains open.
It appears as both keyboard and popover present on screen at the same time, which I don't want.
I am able to get whether the keyboard is opened or not by setting a flag in keyboard notification methods and also the last text field that was edited through text filed delegates. And have tried
[self endEditing: YES]; (as it is in a table cell)
[lastEditedTextField resignFirstResponder];
Even try to pass keyboard dismiss the notification by my self (without knowing whether it is possible or not)
[[NSNotificationCenter defaultCenter] postNotificationName:UIKeyboardWillHideNotification object:nil];
but nothing is working.
How can I dismiss keyboard (if already open) whenever popover appears?
You can call:
[self.view endEditing:YES];
But, a better solution is likely to present the picker using the UIResponder
inputView so it automatically replaces the keyboard and you don't need to mediate between 2 different things (and the user doesn't switch between different parts of the screen potentially).
Try to implement textFieldShouldBeginEditing: and inside it check which text field is this. If it is one of the fields that should display a popover, first call [self.view endEditing:YES] to hide the keyboard, then present the popover and return NO. This way the text field won't take first responder status and the keyboard will not appear again. And if it is one of the "normal" text fields, just return YES.

When/How does a UITextView become a First Responder?

I'm new to iOS development and have recently learned that to make the on screen keyboard disappear we must always call resignFirstResponder on the text view. This causes the text view to relinquish it's first responder status, and hence the keyboard disappears, since there is no need for the text view to respond.
However I also noticed that there's the becomeFirstResponder method to make a view a first responder. However, this method is never called on the text view. So when/how does a textview become first responder when that method is never called?(at least, by me. I'm unsure if it is called elsewhere in the system)
My theory is that is has to already be a first responder before it can resign the first responder status.
firstResponder status is automatically handled for you when a user taps on the text field. So long as user interaction is enabled for the UITextField/UITextView, the keyboard should appear when tapped.
You can monitor for it using the delegate method textViewDidBeginEditiing or, more broadly, by listening for keyboard appearance notifications (UIKeyboardWillShowNotification and UIKeyboardDidShowNotification).
Further, there are ways to dismiss the keyboard without the need of calling the corresponding method resignFirstResponder (such as calling endEditing: on a container view, or setting a scroll view's UIScrollViewKeyboardDismissMode).
Note: In the simulator, it is possible that the keyboard still doesn't appear even if all is correctly working. In that case you just want to make sure keyboard hardware is toggled (CMD+K) for the simulator.
You call becomeFirstResponder yourself if you want to give a UITextField focus and show the keyboard.
This is useful for view controllers that are basically forms. For example, if a user presses a "Sign Up" button, you might push a view controller with a couple of text fields and call becomeFirstResponder on the first one to automatically give it focus and open the keyboard.

hide keyboard in secondary viewcontrollers when pressing background storyboard

I've been scourging the internet and saw several promising answers but none that worked for me. The problem I have is that I have many ViewControllers that I placed in Storyboard mode.
Lets say in my 5th view controller I have some TextViews and TextFields that pops up a keyboard for user input when pressed. However I want to be able to hide the keyboard when I press the background.
I tried following the first and second responses here: How to dismiss number pad keyboard by tapping anywhere
But I dont think my set up is exactly the same as theirs.
Can someone please help me? Please be VERY SPECIFIC if possible and dont assume I know how to fill in the dots.
Thanks so much!!
edit. sorry for not being clear but I meant I want the app to dismiss the keyboard when the user presses anywhere on the screen (thats not another Text field/view). The link I show does this but my problem is that I am storyboarding so I have multiple UIViewControllers and I'm not sure how to get IBOutlets/IBActions to work for the "secondary" viewcontrollers. They only show up under the first/main one...
In your application delegate file,
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.window endEditing:YES];
}
you can use [self.view endEditing:YES];
have a look at the Apple docs for Ending a View Editing Session

UITextField that is always first responder

I have a ViewController that is just a textfield, a next button, and a back button. I want the text field to always be editable while having the keyboard always present. I also want to customize the keyboard to be my own, but that will come once I figure this part out.
EDIT: The keyboard in my case will only actually be a keypad with 10 digits and a backspace key
What is the best way to go about this? I've been working around with having a UITextField that works with a custom keyboard view, and then make that the first responder when the view loads, but maybe there are better ways.
Thanks in advance!
To make a UITextField always use the keyboard...
In the viewDidAppear or viewWllAppear function do this...
[self.textField becomeFirstResponder];
This will make the keyboard appear and the textField respond to the input.
To dismiss the keyboard you have to run...
[self.textField resignFirstResponder];
As long as you don't run this it will keep keyboard focus.
In the view controller's viewWillAppear: method you can call becomeFirstResponder on the text field. This will make the keyboard appear automatically when the view controller appears. As long as there is no other way to dismiss the keyboard, that is all you need.
Of course on the iPad there is a button on the keyboard to dismiss it. If you want to stop that button from working then implement the following delegate method:
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
return NO;
}
And in case you want to really have your own keyboard. create a view properly sized and beautified ;).. and put in the textFiled's inputView property.
textField.inputView = your custom keyboard view
Cheers.

How can I avoid the iPad keyboard to be dismissed when I invoke resignFirstResponder?

How can I avoid the iPad keyboard to be dismissed when I invoke
[textField resignFirstResponder];
Since, the focus is moving from a the previous textField to the new one, I want to keyboard to remain where it is.
thanks
There is no need to call resignFirstResponder to change focus from one TextField to Another.
Just call becomeFirstResponder on the testfield you want to focus.
don't call resignFirstResponder just let the other textfield call
[textField2 becomeFirstResponder];
The Keyboard should stay and the second textfield becomes active

Resources