views:

2237

answers:

5

I want to create a view that consists solely of a UITextView. When the view is first shown, by default, I'd like the keyboard to be visible and ready for text entry. This way, the user does not have to touch the UITextView first in order to begin editing.

Is this possible? I see the class has a notification called UITextViewTextDidBeginEditingNotification but I'm not sure how to send that, or if that is even the right approach.

+14  A: 

Hello, to accomplish that just send the becomeFirstResponder message to your UITextField, as follows (assuming you have an outlet called textField, pointing to the field in question):

- (void)viewWillAppear:(BOOL)flag {
    [super viewWillAppear:flag];
    [textField becomeFirstResponder];
}

Hope this helps!

Adam

Adam Alexander
I just found this. For me viewWillAppear doesn't work but viewDidAppear seems to do the job!
Shaun Austin
That is interesting because viewWillAppear and viewDidAppear are both defined on UIViewController. Looking at my answer again I noticed I forgot to invoke super so I edited my answer to include that line. If that was not the cause of the issue you had I am out of ideas but glad you found a fix!
Adam Alexander
A: 

I also have the same problem , and it is a UitextView instance not UiTextFeild. the above code doesnt work for UITextView :(

A: 

I also have the same problem , and it is a UitextView instance not UiTextFeild. the above code doesnt work for UITextView :(

Yes it does, because it is also UIResponder (just like UITextField).

A: 

Its working with textview

Jatin
A: 

Its working with textview! sdk 3.1.2

lupu1001