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.
Asked
Active
Viewed 2,613 times
2 Answers
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