10

I only know few ways to show a keyboard on iOS

touch textfield,search bar,textview.....

Is it can via touch a button to show keyboard ???

I wish I can use this way to set a button tittle if the button is no tittle or can rename it.

Thank you guys~

Webber Lai
  • 2,014
  • 5
  • 35
  • 66
  • Basically you need to create a control that can become first responder and implements UITextTraits, then when that control becomes first responder, the keyboard will show if it's not showing already. – Jason Coco Dec 08 '10 at 04:13

4 Answers4

15

You need to add an UITextField to your view and call then [myTextfield becomeFirstResponder]; Its possible to set the hidden attrribute from UITextField to YES - so the user will never see the textfield. After Keyboard input is finished you can remove the UITextField with removeFromSuperview.

Maybe a little bit dirty, but thats the solution I used often. I wonder if the SDK provide another possibility.

Venk
  • 5,949
  • 9
  • 41
  • 52
Constantin
  • 8,721
  • 13
  • 75
  • 126
  • I don't know...maybe I can add a textfield into a button and make it hidden – Webber Lai Dec 08 '10 at 06:08
  • Don't need to - it can be somewhere else in your view, too! important is only, that you call becomeFirstResponder when your button is clicked - than will the keyboard appear. You can dynamically change the Button Text (i.e. using the UITextFieldDelegate Protocol). – Constantin Dec 08 '10 at 06:13
  • There is a better solution below using UIKeyInput protocol. – Denis Kutlubaev Jun 29 '13 at 16:58
6

The documentation for the UIKeyInput protocol says the following:

A subclass of UIResponder can adopt this protocol to implement simple text entry. When instances of this subclass are the first responder, the system keyboard is displayed.

Only a small subset of the available keyboards and languages are available to classes that adopt this protocol.

So this might serve your needs better than a hidden text field/view.

Community
  • 1
  • 1
Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302
  • Perfect solution. It works and you just need to add a protocol to your class. @interface UIBubbleTableViewCell : UITableViewCell – Denis Kutlubaev Jun 29 '13 at 16:56
  • 1
    Great. Just to help: You need your class to override "canBecomeFirstResponder" and return YES to get this to work, as well as implement insertText, hasText and deleteBackward. – narco Jun 30 '16 at 22:19
3

You need some form of input method like a UITextField in which you can input a name for your button. If you want, you could create a UIButton that shows the textField (have it hidden by default) and makes it first responder by doing:

textField.hidden = NO;
[textField becomeFirstResponder];

Once you enter something you want in your text field, you can make it so the keyboard disappears, the textfield is hidden, and the UIButton text is changed to the text entered.

-(BOOL)textFieldShouldReturn:(UITextField*)textField; {
textField.hidden = YES;
[textField resignFirstResponder];
[yourButton setTitle:textField.text forState:UIControlStateNormal];
}
sudo rm -rf
  • 29,408
  • 19
  • 102
  • 161
  • what if I don't want to via textfield ?your textfield.hidden = No;that means user will see the textfield .No solution to hide this ?or not using textfield ? – Webber Lai Dec 08 '10 at 05:54
  • You could make the textfield hard to see by changing it's border. – sudo rm -rf Dec 08 '10 at 14:02
2

http://www.iphonedevsdk.com/forum/iphone-sdk-development/17681-show-keyboard-button-press.html

Based on the above info, you could have the text box invisible and the button label constantly change based on the text box text.

Hope this helps :D

Linuxmint
  • 4,716
  • 11
  • 44
  • 64