2

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!

sbjluke
  • 309
  • 5
  • 15
  • What is the custom keyboard? Do you really need to make one? Every single app I've used with a custom keyboard is truly terrible. The keyboard alone has put me off so much that I've deleted the app. – Fogmeister Feb 11 '13 at 23:06
  • Well it's actually just a KeyPad. I only need the digits. Also, check out the Scorekeeper XL app. I think his keyboard is beautiful. – sbjluke Feb 11 '13 at 23:11
  • I'll take a look at that app but if you just need a numpad and backspace keyboard then you can set the keyboard style natively to do this. – Fogmeister Feb 11 '13 at 23:14
  • 1
    If you only want the keypad then set the text field's keyboardType to `UIKeyboardTypeNumberPad`. – rmaddy Feb 11 '13 at 23:14
  • Yes I understand that, What I really want to know is how to make the keyboard be there as the view appears, without it sliding up the second it appears – sbjluke Feb 11 '13 at 23:18
  • @sbjluke See the answers for that. Use `viewWillAppear:`. – rmaddy Feb 11 '13 at 23:21

3 Answers3

1

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.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
  • There is no need to implement the `textFieldShouldReturn` method. That is not associated with the keyboard going away or not. – rmaddy Feb 11 '13 at 23:11
  • Ah, good point. I tend to override it anyway for other reasons but I was thinking the same. – Fogmeister Feb 11 '13 at 23:12
0

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;
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

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.

devluv
  • 2,007
  • 13
  • 13