问题
I have a view built through IB, there's a text view and and button on it. When the view shows up I would like to have the keyboard to be already displayed.
I tried to set the first responder in the didViewLoad but that didn't work.
I do have an IBOutlet that is connected to the textView and related accessor.
回答1:
Looks like you may have accidentally misspelled the method name didViewLoad instead of viewDidLoad. All you should need there (assuming your IBOutlet is connected in IB) is the following:
[textView becomeFirstResponder];
回答2:
I know this is tagged as cocoa-touch but this is highly ranked in Google and I ran into trouble with using -becomeFirstResponder on OS X; it did nothing. From the NSResponder documentation,
Use the NSWindow
makeFirstResponder:
method, not this method, to make an object the first responder. Never invoke this method directly.
So on OS X use,
[[myView window] makeFirstResponder:myView];
回答3:
For Swift
textView.becomeFirstResponder()
来源:https://stackoverflow.com/questions/1422733/how-do-i-set-the-firstresponder