Reputation: 2207
I would like the keyboard to appear automatically when a certain UITextView
appears. Right now, the first time the UITextView
appears, the user has to tap on it for the keyboard to appear. Subsequent appearances of the UITextView
automatically make the keyboard appear. How can I make this happen the first time the UITextView
appears as well?
-(void)displayComposeScreen
{
[self.nameField resignFirstResponder]; //This is a different UITextView, but my issue doesn't change whether I leave this line in or take it out
if (!self.textView)
{
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 20, 280, 150)]; //This is the UITextView with whose appearance I want the keyboard to appear automatically.
self.textView.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
self.textView.delegate = self;
}
[self.textView becomeFirstResponder];
self.textView.hidden=NO;
if (self.ghhaiku.userIsEditing==NO)
{
self.textView.text = @"";
}
else
{
self.textView.text = self.ghhaiku.text;
}
[self.view addSubview:self.textView];
}
Basically, the first time this method is called the user has to tap on self.textView
for the keyboard to appear, and I want the keyboard to appear automatically when the method is called, like it is on subsequent calls of this method.
Upvotes: 1
Views: 4331
Reputation: 465
[UIView animateWithDuration:0.0 animations:^{
[self addSubview:textview];
} completion:^(BOOL finished){
[textview becomeFirstResponder];
}];
Upvotes: -1
Reputation: 2005
Hope to help you
[textField performSelector:@selector(becomeFirstResponder)
withObject:nil
afterDelay:0.2f]
In iOS 6, -[UITextField becomeFirstResponder] doesn't work in -viewWillAppear: (comment to question by https://stackoverflow.com/users/1162777/anton)
Upvotes: 2
Reputation: 3679
You should put the code
[self.textView becomeFirstResponder]
after you have put the text view into the controller's view.
Upvotes: 3
Reputation: 4712
Try following line when you want to active the textView.
[self.textView becomeFirstResponder];
Upvotes: 0