Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deselect selected text in an iPad application

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.

like image 954
Robert Stewart Avatar asked Nov 03 '10 20:11

Robert Stewart


2 Answers

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

Like this:

myWebView.userInteractionEnabled = NO;
myWebView.userInteractionEnabled = YES;
like image 192
Yurii Soldak Avatar answered Sep 20 '22 15:09

Yurii Soldak


A cleaner solution:

Swift

webView.endEditing(true)

Objective-C

[webView endEditing:YES]
like image 38
Rudolf Adamkovič Avatar answered Sep 20 '22 15:09

Rudolf Adamkovič