【发布时间】:2015-07-07 19:00:20
【问题描述】:
在输入中文文本时,先输入英文字符,然后选择中文字符,在选择中文字符之前,英文字符处于选中状态(-markedRange)。
在使用 ReactiveCocoa 之前,我可以这样做:
在UITextField's UIControlEventEditingChanged事件回调中:
const NSUInteger limitLength = 10;
NSString *tobeString = textField.text;
UITextRange *selectedRange = [textField markedTextRange];
BOOL nothingSelected = (selectedRange==nil || selectedRange.isEmpty);
if (nothingSelected) {
if (tobeString.length > addressItemNameLimitLength) {
textField.text = [tobeString substringToIndex:limitLength];
}
}
self.textField.text = textField.text;
但是在MVVM with ReactiveCocoa中,我的view model中无法获得对UITextField的引用,如何同时获得文本字段的marked range和text?
【问题讨论】:
标签: ios mvvm reactive-cocoa