So I did the following:
idtextInput = nil;
if ([ self.aTextView isFirstResponder]) {
textInput = self.aTextView;
} else if ([self.aTextField isFirstResponder]) {
textInput = self.aTextField;
}
if (textInput != nil) {
UITextRange * selectedRange = textInput.selectedTextRange;
// ...
}
Only in selectedTextRange Immediately crash on the attribute “Unrecognized selector sent to instance”.
What am I doing wrong?
[Edit: It seems to work in iOS 5, but it crashes on the device in iOS 4. Is this a change in iOS 5? The document says that the protocol is 3.2.]
The answer to this question shows that the consistency with UITextInput is iOS 5 : Can I select a specific block of text in a UITextField? New feature. Therefore, the protocol itself seems to be iOS 3.2, but UITextView/Field did not use the protocol before iOS 5.
p>
UITextField and UITextView both adopt the UITextInput protocol. The selectedRange property of UITextView returns NSRange, where UITextField does not have any selection properties/methods. I want to use a routine to manage the insertion in UITextField or UITextView.
So I did the following:
idtextInput = nil;
if ([self.aTextView isFirstResponder]) {
textInput = self.aTextView;
} else if ([self.aTextField isFirstResponder]) {
textInput = self.aTextField;
}
if (textInput != nil) {
UITextRange * selectedRange = textInput.selectedTextRange;
// ...
}
It just crashes immediately on the selectedTextRange property “cannot The identified selector is sent to the instance”.
What am I doing wrong?
[Edit: It seems to work in iOS 5, but it crashes on the device in iOS 4. Is this a change in iOS 5? The document says that the protocol is 3.2.]
I verified in my application that both UITextView and UITextField crashed – [UITextView selectedTextRange]: iOS 4 simulator Unrecognized selector in the iOS 5 simulator, but not the iOS 5 simulator.
The answer to this question shows that the consistency with UITextInput is iOS 5: Can I select a specific block of text in a UITextField New features in ?. Therefore, the protocol itself seems to be iOS 3.2, but UITextView/Field did not use the protocol before iOS 5.