ios - RubyMotion:在 UITextField 中查找每个字符条目

标签 ios delegates rubymotion

我是 RubyMotion for iOS 应用程序的新手,但我使用 Objective C 进行编码。

我的要求是获取应为 UITextField 中的每个字符类型调用的委托(delegate)方法。

objective-c :我使用“shouldChangeCharactersInRange”来查找用户字符条目。

谁能建议我如何在 RubyMotion 中实现此功能以跟踪 UITextField 中的字符类型

谢谢。

问候。

最佳答案

首先,当您创建文本字段时,请确保将委托(delegate)设置为它所在的同一 View Controller 类:

textField = UITextField.alloc.initWithFrame([[10,200],[300,40]])
textField.delegate = self

然后将此方法添加到该类:

def textField(textField, shouldChangeCharactersInRange:range, replacementString:string)
  # return true or false based on whether you want to allow the replacement
  true
end

关于ios - RubyMotion:在 UITextField 中查找每个字符条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11020039/

相关文章:

ios - 没有为应用程序 'aps-environment' 找到有效的 'MyApp' 授权字符串 : (null). 通知将不会被传递

ios - 在 UITableView 中,我如何知道一行的 scrollRectToVisible 何时完成?

ios - addArrangedSubview 与 addSubview

iphone - 你能在 Cocoa Touch 中获得系统接听电话按钮吗?

java - 委托(delegate)封闭类的专有名称是什么?

ruby - sprintf 在 RubyMotion 中损坏

ios - 在 Cloudkit 中使用子查询

c# - 使用委托(delegate)和事件从另一个表单更新表单

c++ - 为什么委托(delegate)或闭包通常被称为 true "object-oriented function pointers"?

ruby - 将 MKStorekit 与 Rubymotion 结合使用