Force keyboard to show up via button (iOS)

后端 未结 1 1724
执笔经年
执笔经年 2021-01-13 05:34

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         


        
相关标签:
1条回答
  • 2021-01-13 06:07

    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;
    }
    
    0 讨论(0)
提交回复
热议问题