Search code examples
iosuitextfielduikeyboardfirst-responder

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!


Solution

  • 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.