I want to get the current pos开发者_StackOverflow中文版ition of cursor when I first click on a UITextView that contains some text.
I believe the UITextView selectedRange
property should provide what you're after.
you could use UITextView's selectedRange to return the insertion point pf text. The below code shows how to it.
NSString *contentsToAdd = @"some string";
NSRange cursorPosition = [tf selectedRange];
NSMutableString *tfContent = [[NSMutableString alloc] initWithString:[tf text]];
[tfContent insertString:contentsToAdd atIndex:cursorPosition.location];
[theTextField setText:tfContent];
[tfContent release];
for More to read the SO Post
Getting cursor position in a UITextView on the iPhone?
Also read the same on Apple discussion forum.
http://discussions.apple.com/thread.jspa?messageID=9940169
精彩评论