iOS – UITEXTILD and UITEXTVIEW UITEXTINPUT protocol used to manage the selection results in crash

Both UITextField and UITextView use 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:

id 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 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.]

I verified in my application that both UITextView and UITextField It crashed – [UITextView selectedTextRange]: Unrecognized selector in iOS 4 simulator, but not 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 feature. Therefore, the protocol itself seems to be iOS 3.2, but UITextView/Field did not use the protocol before iOS 5.

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:

id textInput = 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.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3908 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.