views:

153

answers:

1

I have a UITextView that is properly displaying URLs thusly:

contentView.editable = NO;
contentView.dataDetectorTypes = UIDataDetectorTypeAll;

My goal is to make it so you can still tap on this text view in order to edit its text at a particular location (just like the built-in Notes app). That way, if you tap a link, it'll launch a browser, but if you tap anywhere else, it'll start editing at the point where you tapped. Should be easy, right?

Not so far. Subclassing the UITextView and overriding touchesEnded gives you a chance to set editable to YES. But when you do that, the text view doesn't remember where you tapped (the selectedRange doesn't get set properly), so editing always begins at the bottom of the text view.

I've even tried using the undocumented setSelectionWithPoint method, but it doesn't behave as you'd expect.

Can anyone think of some way to achieve a proper tap-to-edit UITextView with tappable links?

A: 

Perhaps you could try either retaining the UITouch and UIEvent or forging copies using custom classes that have the same class signatures, then re-send the touchesBegan: and touchesEnded: events after setting editable to YES.

Ed Marty
Right, I tried that, but unfortunately UITextView seems to do most of its own touch processing. Re-sending the touchesBegan: and touchesEnded: events to the superclass of my custom UITextView doesn't produce the desired result, namely the simulation of tapping the UITextView.Digging into UITextView a little, it looks like there might be lower level mouseUp and mouseDown events. I'm not sure how to access them though.
John Seacrest