UITextView的expertFirstResponsder不能正常工作 [英] UITextView's becomeFirstResponsder not working proprly

查看:250
本文介绍了UITextView的expertFirstResponsder不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIView ,带有 UITextView UITextField 作为子视图。我希望键盘自动出现在 textFieldShouldReturn 来电。

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;
}

但这不起作用由于某种原因,它显示键盘上的光标文本视图中的下一行。我试图在textview中设置文本nil,但它会自动调用 textDidChange 方法,并且光标在没有任何文本的新行上移动。

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.

同样的技巧适用于 UITextField ,它也适用于iOS 5.0,但如何在iOS 4.3中解决此问题。如果您有任何其他选择,请告诉我。

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?

推荐答案

在iOS中有一个已知的错误,它在同一个runloop中辞职并成为第一响应者。请尝试以下

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];

这篇关于UITextView的expertFirstResponsder不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆