[ACCEPTED]-How do I give a UITextView focus programmatically?-uikit
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];
Swift:
textView.becomeFirstResponder()
0
That does seem somewhat hackish.
The Cocoa 7 Touch terminology for 'having focus' is 6 'first responder' and UITextView
s 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]; }
[textView becomeFirstResponder];
0
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() {
super.viewDidLoad()
textView.becomeFirstResponder()
}
I 1 find this works without any errors
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.