UITextView becomeFirstResponder 使用 iOS SDK 8.2 失败

Posted

技术标签:

【中文标题】UITextView becomeFirstResponder 使用 iOS SDK 8.2 失败【英文标题】:UITextView becomeFirstResponder fails with iOS SDK 8.2 【发布时间】:2015-03-27 06:24:26 【问题描述】:

我试图让 Textview becomeFirstResponder 但失败了。 iOS SDK 7 使用相同的代码运行良好 不知道 iOS SDK 8.2 有什么问题。

我也在检查canBecomeFirstResponder。它为此传递 true,但失败并为 becomeFirstResponder 返回 NO。在这里,我在 viewWillAppear 方法中执行此操作,并在 viewDidAppear 方法中进行了尝试。

代码

if([txtView canBecomeFirstResponder])

    temp = [txtView becomeFirstResponder];

我也发现其他人也有同样的问题,他们建议像下面这样使用。但在我的情况下也不能改变延迟时间。

[txtView performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];

如果我需要根据新的 ios SDK 版本更改任何内容,请提出建议。

【问题讨论】:

它与 Xcode 无关;而是与 iOS SDK 相关。 检查一下你是否设置了txtView的Delegate和IBOutlet是否从XIB或Storyboard正确链接。 @Raptor 好的,感谢您的更新。但是我已经添加了,因为在 iOS8 中它也可以正常运行我的应用商店版本,并且它是使用 xcode 5.X 提交的 @SurajMirajkar 是的。我检查了它的委托和 IBOutlate 正确链接。它也适用于 iOS7。 尝试检查您是否实施了textViewShouldBeginEditing:(UITextView *)textView 委托,这可能会阻止textView 成为第一响应者 【参考方案1】:

我在viewDidLoad 中使用了[txtView becomeFirstResponder];。对我来说效果很好。

【讨论】:

您遇到过上述问题吗?意味着只有最新的 xcode/iOS8.x 才有问题? 不,我已经使用了最新的 xCode 6.1 和 iOS 8.2。请解释一下这行代码“temp = [txtView becomeFirstResponder];”。 是 BOOL 返回是否成为FirstResponder,但我在该变量中得到 NO。

以上是关于UITextView becomeFirstResponder 使用 iOS SDK 8.2 失败的主要内容,如果未能解决你的问题,请参考以下文章

当 UITextView 的文本超出 1 行时展开 UITextView 和 UITableView

选择另一个 UITextView 时,如何阻止 UITextView 退出第一响应者/关闭键盘?

从 UIView 中的 UITextView 复制文本后,UITextView 更改为 UIWebDocumentView?

UITextView 数据变化迅速

UITextView contentInset 在 iOS 7 上的 UITextView 中不起作用?

UITextView 设置属性后做啥?