【问题标题】:UITextField stops working when setting delegate to viewcontroller将委托设置为视图控制器时 UITextField 停止工作
【发布时间】:2014-04-22 18:58:08
【问题描述】:

我不确定为什么会发生这种情况,想知道是否有人可以提供帮助。

我目前有一个 UITextfield 委托设置为 ViewController。我已经声明了所有必要的方法。当我开始输入时,什么都没有显示,但是根据我插入的 NSLog 检测到它。

当我删除委托时,文本字段开始工作。

有什么想法吗?

【问题讨论】:

  • 请在文本字段的委托中发布您正在编写的代码
  • - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 必须返回 YES textField:shouldChangeCharactersInRange:replacementString: 也必须返回 YES
  • 感谢@user2387149。它是 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange 没有返回 YES。我有一个从脚本中复制的 if 条件,该脚本确定当 UITextfield 被键盘覆盖时滚动。
  • 不客气,无论如何都会将其发布为答案,以便人们以正确的方式看到它。

标签: ios uiviewcontroller delegates uitextfield


【解决方案1】:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

必须在某个时候返回 YES

textField:shouldChangeCharactersInRange:replacementString:

也必须返回 YES

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多