سؤال

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~

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

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

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top