user1992686
user1992686

Reputation:

Bringing up the iPhone keyboard by clicking a button?

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

Answers (4)

nsgulliver
nsgulliver

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

Hossam Ghareeb
Hossam Ghareeb

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

Hari1251
Hari1251

Reputation: 452

-(void)ButtonClicked
{
      [textFld becomeFirstResponder];
      [textView becomeFirstResponder];
}

use this method

Upvotes: 0

dsgriffin
dsgriffin

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

Related Questions