UITextField that is always first responder - ios

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.

Related

How do I make inputAccessoryView stay on screen when using drag to dismiss?

I know that the view controller must be firstResponder in order for the inputAccessory to stay at the bottom. I am using a custom inputView / keyboard. I can manually dismiss it with a done button by removing the inputView but not resigning first responder. However when I enable the interactive drag to dismiss on my scrollview, the code automatically resigns first responder. So how can I use the interactive drag to dismiss and yet keep my viewcontroller as first responder? Anyone done this before? I thought maybe it is not possible and that I may need to make my own interactive drag to dismiss using a gesture recognizer.
More info:
I have a button that swaps between standard keyboard and my custom one. I have seen dismissing these cause 2 keyboard did dismiss notifications. I thought I could become firstResponder in the keyboardDidHide method but this didn't work well since I couldn't tell the difference between when I manually dismissed the keyboard and when the interactive drag does it. This matters because I don't need to reload the input view or become first responder when I manually dismiss because I took care of it already.
Any suggestions would be amazing. I am trying to use inputView and inputAccessoryView on the UIViewController level.
Well after a day of pulling my hair, I have an answer.
Using the canResignFirstResponder of my viewcontroller did the trick. In viewWillAppear I set a BOOL responderOverride = YES;
In viewWillDisappear I call
responderOverride = NO;
[self resignFirstResponder];
When the interactive drag on the scrollview tries to resignFirstResponder, canResignFirstResponder returns no which prevents my viewcontroller from resigning and keeps my input accessory retained and sitting at the bottom of the screen.
There is a lot of other code with reloading input views but since the real question was how to force a controller to stay first responder so we don't lose our input accessory view, then this solution works.
override var canBecomeFirstResponder : Bool {
get {
retrun true
}
}
This works for me

iOS - Automatically Have Keyboard Toggled On ViewController

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];

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.

Automatic keyboard xcode

I am new to iOS development. I need to make my keyboard appear when I enter the view without pressing anything; for example when I have a view with a textField, when I enter the view, I want the keyboard to appear automatically. How can this be done?
You need to make the textField to become the first responder. Try to call this method in the viewDidAppear method of the view controller that contains the textField.
[textField becomeFirstResponder];
Use [yourTextField becomeFirstResponder] method call in your class's viewDidAppear or viewDidLoad.

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