5

I have a custom menu item (UIMenuItem) attached to a UIWebView. When the user selects my custom menu item after selecting some text in the web view, I want to "deslect" the current text selection. The problem is that the edit menu will pop up again when I show a modal form for some reason, I think because there is still a selected (highlighted) text range. I want to programmatically "unselect" the selected text in my custom menu item handler, after I've captured the selected range.

Robert Stewart
  • 201
  • 5
  • 10

2 Answers2

6

Use UIView's userInteractionEnabled property. Just disable user interaction and enable it back.

Like this:

myWebView.userInteractionEnabled = NO;
myWebView.userInteractionEnabled = YES;
Yurii Soldak
  • 1,458
  • 4
  • 19
  • 24
5

A cleaner solution:

Swift

webView.endEditing(true)

Objective-C

[webView endEditing:YES]
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118