我有一个控制器,它接受自定义键输入并以独特的方式显示它。它成为关键响应者并实现UIKeyInput
。
https://developer.apple.com/reference/uikit/uikeyinput
它是在 8.0 中实现的,在 iOS 键盘上的预输入功能之前。我正在为 10.0 更新它,但它不能很好地管理交互。
- (void)deleteBackward {
NSString *text = self.codedLabel.text;
if (text.length > 0) {
text = [text substringToIndex:text.length-1];
}
self.codedLabel.text = text;
self.decodeLabel.text = [text stringByReplacingOccurrencesOfString:@"\n" withString:@" | "];
[self saveText:text];
}
- (BOOL)hasText {
NSString *text = self.codedLabel.text;
return (text.length > 0);
}
- (void)insertText:(NSString *)newtext {
NSString *text = self.codedLabel.text;
text = [text stringByAppendingString:newtext];
self.codedLabel.text = text;
self.decodeLabel.text = [text stringByReplacingOccurrencesOfString:@"\n" withString:@" | "];
[self saveText:text];
}
When one of the type ahead words is selected, insertText:
is invoked, but the newtext
value is always 0xa000000000000201
and the debug output is
(lldb) po newtext
(lldb) p newtext.length
(NSUInteger) $1 = 1