Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView's becomeFirstResponsder not working proprly

I have a UIView with a UITextView and UITextField as a subview. I want the keyboard to appear automatically on textFieldShouldReturn call.

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [textView becomeFirstResponder];
    return YES;
}

but this does not work AND for some reason, it displays keyboard with cursor on next line in text view . I tried to set text nil in textview but it automatically call textDidChange method and cursor moves on new line without any text.

enter image description here

This same technique works correctly for a UITextField and also it works fine with iOS 5.0 but how to fix this in iOS 4.3. Let me know if you have any alternative as well.

Am I missing something obvious?

like image 302
Paras Gandhi Avatar asked Dec 29 '11 15:12

Paras Gandhi


1 Answers

There's a known bug in iOS with resigning and becoming first responder within the same runloop. Try the following

[textField resignFirstResponder];
[textView performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
like image 126
lorean Avatar answered Oct 19 '22 23:10

lorean