Reputation:
How can I bring up the iphone keyboard by clicking a button - I haven't created any text fields. My intention is to have labels that hold a single character.
Other people have asked this and it has been answered but it was from years ago and I didn't understand what people meant in there responses.
Thank you for any help in advance.
Upvotes: 4
Views: 1089
Reputation: 12671
Only way you could do this is via hidden UITextField
, and set that textField to becomeFirstResponder
you could hide the text field in your code liket his textfield.hidden=YES;
or you could hide the textfield from nib file also by going into the attribute inspector and tick the Hidden
property
You could have a look at this UIKeyInput- Displaying keyboard in iPhone without UITextField or UITextView, I have not tried myself this
Upvotes: 2
Reputation: 7123
You can add a hidden UITextFeild
as tempTF
and when the button clicked. call becomeFirstResponder
of this textFeild
:
[self.tempTF becomeFirstResponder];
To Hide textField:
UITextField *tempTF = [[UITextField alloc] init];
tempTF.hidden = YES
or mark Hidden ir your Interface Builder
Upvotes: 0
Reputation: 452
-(void)ButtonClicked
{
[textFld becomeFirstResponder];
[textView becomeFirstResponder];
}
use this method
Upvotes: 0
Reputation: 68626
Attach the button to a touchUpInside event and call becomeFirstResponder on the textView
or textfield
:
Here is an example (to bring it up when a text view is clicked):
-(IBAction)buttonClicked:(id)sender{
[textView becomeFirstResponder];
}
Upvotes: 0