[ACCEPTED]-How do I give a UITextView focus programmatically?-uikit

Accepted answer
Score: 168

Since UITextView inherits from UIResponder (indirectly, it actually 5 inherits from UIScrollView, which inherits from UIView which 4 then inherits from UIResponder) you can call the -becomeFirstResponder method 3 on your text field, which will cause it 2 to become the first responder and begin 1 editing:

[textView becomeFirstResponder];
Score: 32




Score: 12

That does seem somewhat hackish.

The Cocoa 7 Touch terminology for 'having focus' is 6 'first responder' and UITextViews will display their 5 keyboards when they are the first responder. I 4 can think of several techniques to make 3 the UITextView become the first responder, but 2 the easiest is probably in your view controller's 1 viewWillAppear or viewDidAppear methods:

- (void)viewWillAppear:(BOOL)animated

    [myTextView becomeFirstResponder];

    [super viewWillAppear:animated];
Score: 7
[textView becomeFirstResponder];


Score: 1

When you want the focus to be that particular 4 TextView on loading a ViewController, you 3 can place the textView.becomeFirstResponder() in 2 the ViewDidLoad overrode func as below:

 override func viewDidLoad() {



I 1 find this works without any errors

More Related questions