How to show a keyboard via press a NSButton?

泪湿孤枕 提交于 2019-12-18 20:09:17

问题


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~


回答1:


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.




回答2:


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.




回答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];
}



回答4:


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



来源:https://stackoverflow.com/questions/4384072/how-to-show-a-keyboard-via-press-a-nsbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!