我有一个自定义的UITextField
类,我想在其中覆盖
override func shouldChangeText(in range: UITextRange, replacementText text: String) -> Bool
但是我无法获得新的更改字符串
override func shouldChangeText(in range: UITextRange, replacementText text: String) -> Bool {
if (self.changeHandler != nil) {
let location = offset(from: beginningOfDocument, to: range.start)
let length = offset(from: range.start, to: range.end)
let r = Range(NSRange(location: location, length: length))
let newText = self.text!.replacingCharacters(in: r!, with: text)
return self.changeHandler!(newText)
}
return super.shouldChangeText(in: range, replacementText: text)
}
我明白了 对成员“文本”的含糊不清