UITextField and UITextView both adopt the UITextInput protocol. UITextView's selectedRange property returns NSRange, where UITextField doesn't have any selection properties/methods. I'd like to use one routine to manage insertion in either UITextField or UITextView.
So I do the following:
id<UITextInput> textInput = nil;
if ([self.aTextView isFirstResponder]) {
textInput = self.aTextView;
} else if ([self.aTextField isFirstResponder]) {
textInput = self.aTextField;
}
if (textInput != nil) {
UITextRange * selectedRange = textInput.selectedTextRange;
// ...
}
Only to promptly crash with 'unrecognized selector sent to instance' on the selectedTextRange property.
What am I doing wrong?
[EDIT: seems to work in iOS 5, but crashes on device in iOS 4. Is this a change in iOS 5? The docs say the protocol is 3.2+.]