Reputation: 11
I want to get the current position of cursor when I first click on a UITextView that contains some text.
Upvotes: 1
Views: 3058
Reputation: 31722
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
Upvotes: 1
Reputation: 54445
I believe the UITextView selectedRange
property should provide what you're after.
Upvotes: 1