5

I have an UITextView and I don't want check editable option, how can call keyboard via a button? This code doesn't work for me!

-(IBAction) yourButtonClick
{
    [myTextView becomeFirstResponder];
    [self.view addSubview:myTextView]; 
}

1 Answer 1

23

From the iPhone Application Programming Guide

However, you can programmatically display the keyboard for an editable text view by calling that view’s becomeFirstResponder method. Calling this method makes the target view the first responder and begins the editing process just as if the user had tapped on the view.

So to show the keyboard programmatically,

[textView becomeFirstResponder];

However, the keyboard will never show if the textView is not editable.

The purpose of showing the keyboard is to allow editing. I assume you just don't want the keyboard to appear when the user taps the text view. In this case, you can enable editable programmatically when the button is tapped.

-(IBAction) yourButtonClick
{
     myText.editable = YES;
     [myText becomeFirstResponder];

}

Then in the UITextViewDelegate, disable editable when the user finishes editing.

- (void)textViewDidEndEditing:(UITextView *)textView {
  textView.editable = NO;
}
2
  • ahaaaaa thank you very much i add this code textPad.editable = YES; and works great
    – iOS.Lover
    May 1, 2010 at 15:36
  • Hi Arrix, is there a way to programatically invoke Landscape soft keyboard in Portrait view ?
    – locknies
    May 6, 2014 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.