Hello all,
I'm using an UITextView
to hold static content (in Chinese, which means that the characters are all fixed width). I want to let users click on a character in the text and bring up dictionary information for that character. I know all of the issues surrounding the lack of copy and paste and all that, but I'm hoping that there will be a way to do this without waiting for the iPhone 3.0 firmware.
At first, I thought about using UITextView
s selectedIndex
property. Unfortunately, when the UITextView
is not editable, the following code in the UITextView
's always returns the length of the entire text block:
NSRange touchPoint = self.selectedRange;
NSLog(@"Selection: %d", touchPoint.location);
This makes sense, I suppose, as with a non-editable UITextView
there's no way to select an insertion point, but it's doesn't help me any. :)
Another approach would be to calculate, using the fact that the Chinese text is fixed width, where the click landed and what text should be under that location at the time, but this is complicated by punctuation which can cause a line to wrap early, bringing preceding characters down a line.
Is there another way of know what text is under a touch event that I'm missing?