18

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.

amok
  • 1,736
  • 4
  • 20
  • 41
  • Check out this link : http://juliuspaintings.co.uk/cgi-bin/paint_css/animatedPaint/004-TextFieldApp.pl This most likely has your answers. – Dyn Jul 08 '11 at 18:51

3 Answers3

48

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];
jlehr
  • 15,557
  • 5
  • 43
  • 45
  • 5
    That should be [textView.window makeFirstResponder:textView]; – voidref Jul 15 '13 at 18:12
  • 6
    @voidref You'd be correct if the question was about Cocoa but it's not, it's about Cocoa touch. There's no `makeFirstResponder:` method in `UIWindow`. – jlehr Jul 15 '13 at 23:16
19

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];
Daniel Farrell
  • 9,316
  • 8
  • 39
  • 62
  • 3
    If you are using IB, the `NSWindow` has a `initialFirstResponder` Outlet that allows you to connect a view that will be the first responder when the window is first drawn on screen. – Mojo66 Sep 20 '19 at 10:12
-1

For Swift

textView.becomeFirstResponder()
Bilbo Baggins
  • 3,644
  • 8
  • 40
  • 64