好问题。但似乎UITextInputDelegate
不是一个协议you实施。
来自苹果文档,标题为底层文本处理技术 https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/LowerLevelText-HandlingTechnologies/LowerLevelText-HandlingTechnologies.html:
当文本视图由于外部原因发生变化时,即:
它们不是由来自文本输入系统的调用引起的 -UITextInput
对象应该发送textWillChange:
, textDidChange:
,
selectionWillChange:
, and selectionDidChange:
发送至输入的消息
delegate(它持有对它的引用)。例如,当用户点击
文本视图,您可以设置所选文本的范围以放置
手指下的插入点,您将发送selectionWillChange:
在更改所选范围并发送之前selectionDidChange:
更改范围后。
并从docs https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputDelegate_Protocol/#//apple_ref/occ/intfm/UITextInputDelegate/textWillChange:在 UITextInputDelegate 上:
UIKit 提供了一个私有文本输入委托,它在
运行时到其类采用的对象的 inputDelegate 属性
UITextInput 协议。
上述的含义是我们不执行这些委托方法;我们用它们来通知inputDelegate
您已通过键盘输入以外的方式更改了文本或选择。
这是一个example https://searchcode.com/codesearch/view/68050187/#l-2098说明这一点的方法:
- (void)delete:(id)sender;
{
if (selection && ![selection isEmpty]) {
[inputDelegate textWillChange:self];
[inputDelegate selectionWillChange:self];
[self replaceRange:selection withText:@""];
[inputDelegate selectionDidChange:self];
[inputDelegate textDidChange:self];
}
}
带有更多示例的示例代码here https://searchcode.com/codesearch/view/68050187/#l-2098.