Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a keyboard via press a NSButton?

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~

like image 724
Webber Lai Avatar asked Dec 08 '10 04:12

Webber Lai


3 Answers

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.

like image 60
Kristopher Johnson Avatar answered Oct 19 '22 22:10

Kristopher Johnson


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.

like image 22
Constantin Avatar answered Oct 20 '22 00:10

Constantin


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];
}
like image 45
sudo rm -rf Avatar answered Oct 20 '22 00:10

sudo rm -rf