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.
Use UIView's userInteractionEnabled property. Just disable user interaction and enable it back.
Like this:
myWebView.userInteractionEnabled = NO;
myWebView.userInteractionEnabled = YES;
A cleaner solution:
Swift
webView.endEditing(true)
Objective-C
[webView endEditing:YES]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With