UITextView 的变为FirstResponsder 无法正常工作
我有一个 UIView
,其中包含 UITextView
和 UITextField
作为子视图。我希望键盘在 textFieldShouldReturn
调用时自动出现。
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[textView becomeFirstResponder];
return YES;
}
但这不起作用,并且由于某种原因,它在文本视图的下一行上显示光标的键盘。我尝试在 textview 中设置 text nil,但它会自动调用 textDidChange
方法,并且光标在没有任何文本的情况下移动到新行。
同样的技术适用于 UITextField
,并且在 iOS 上也能正常工作5.0 但如何在 iOS 4.3 中修复此问题。如果您还有其他选择,请告诉我。
我错过了一些明显的东西吗?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iOS 中存在一个已知的错误,即在同一运行循环中辞职并成为第一响应者。尝试以下操作
There's a known bug in iOS with resigning and becoming first responder within the same runloop. Try the following