I have been looking for a solution for this all morning, but have not yet found something that works.
I have a text view in which there is a certain fixed text that I do not want the user to be able to change. In this case, each of my textual representations begins with "1.", "2." etc. The idea is that the entered text will be numbered for what I do later.
I do not want the user to be able to delete this text (it is essentially "persistent"). I also do not want to let them start adding text in the middle of this preliminary text.
To handle this, I did:
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if (range.location < 3) return NO; return YES; }
This works great, except if the user touches somewhere in the parts "1.", "2." etc., it will set the cursor there, which then prevents the user from entering text due to checking the location of the range. What I want to do in this case is to set the cursor (possibly in textViewDidBeginEditing) to the end of the text in the view. However, no matter what combination of selectedRange I use, I just can't get the rough cursor to move to the end. Any help would be greatly appreciated.
Jason source share