Reputation: 6386
I have a textview and i need to be able to remove the selected text [ i mean i want to delete the text which are highlighted] for that i did as below
Code
(void)textViewDidChangeSelection:(UITextView *)textView {
NSRange range = textView.selectedRange;
myTextView.text = [myTextView.text stringByReplacingCharactersInRange:range withString:@""];
}
but it is crashing , how to implement this functionality here
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds'
Pls let me know
Upvotes: 0
Views: 2660
Reputation: 7733
It's working fine on xcode version 3.2.5. Check the delegates of the UITextView are connected to the file Owner in the Interface Builder.
-(void) textViewDidChangeSelection:(UITextView *)textView {
NSRange range = textView.selectedRange;
myTextView.text = [myTextView.text stringByReplacingCharactersInRange:range withString:@""];
}
Upvotes: 3
Reputation: 643
This code is working in my simulator, please check delegates connection(from UITextView to File owner)and (File owner to UITextView) in Interfacebuilder
Upvotes: 1