3

I have an app with a custom text editor that implements the UITextInput protocol. In iOS 6, Apple added one new required method to the protocol:

- (NSArray *)selectionRectsForRange:(UITextRange *)range

I've implemented this, but I can't seem to find a way to trigger it. At least in the way my app works, it seems to never get called by the text system. Does anyone know what it's used for?

c-had
  • 1,380
  • 1
  • 9
  • 18
  • From the documentation, the return value is `An array of UITextSelectionRect objects that encompass the selection.` Further reading the documentation for `UITextSelectionRect`: If you are implementing a custom text input view, you can subclass and use your custom class to return selection-related information. When subclassing, you should override and reimplement all properties. In your custom implementations, do not call super. – Nandeep Mali Sep 25 '12 at 20:17
  • I might have stated the obvious above and something that you might have already read, but it seems to me this for information on text selection range and returns custom information about what is selected to whoever asks for it. – Nandeep Mali Sep 25 '12 at 20:18
  • Yes, but my question is when is it called. All the methods in the protocol are called by the text system for things like typing and autocorrect. I'm trying to find out when it will call this method. – c-had Sep 25 '12 at 21:02
  • Have you tried selecting the text and dragging along to select more/less text? Add some logs and see if it invokes there. – Nandeep Mali Sep 26 '12 at 10:04

1 Answers1

4

This method is only used by subclasses of UITextView. This is the only method that would give you the system selection and loupe. This is what I was told at WWDC.

I am working on my own DTRichTextEditor as well and I implemented it nevertheless, maybe one day we get the selection/loupes also for our own UIViews that are not derived from UITextView.

Cocoanetics
  • 8,171
  • 2
  • 30
  • 57
  • The method actually *does* get called for custom views when VoiceOver is enabled. The result is then used to highlight lines of text that are spoken while the user drags across the view (tested on iOS 8, not sure how the behavior is on iOS 6 and 7). – omz Feb 01 '15 at 11:53