views:

1508

answers:

3

Hello,

So I want to bring in a modal view controller that has a UITextView in it and I want the keyboard to automatically popup and the UITextView have focus.

I found a way to accomplish this by doing the following:

textView.editable = YES;
textView.editable = NO;

This just seems hacky to me, is there another way?

+13  A: 

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

[textView becomeFirstResponder];
Perspx
Great! Thanks for the help!!
Meroon
+2  A: 

That does seem somewhat hackish.

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

- (void)viewWillAppear:(BOOL)animated
{

    [myTextView becomeFirstResponder];

    [super viewWillAppear:animated];
}
Erik
A: 
[textView becomeFirstResponder];
Corey Floyd