I have a custom cell (subclass of UITableViewCell) with a textView inside of it. It works great! Now, when I tap on a cell and highlight some text, the default UIMenuController appears and I can choose to copy the highlighted text. Also this function works perfectly. Now, I would like to add a custom button to the UIMenuController, which I actually did, but to perform the menu item action I need to know what the selected text is. How can I get it?
Share
To explain this better, there is no method in
UITextFieldthat allows us to know what the currently selected text is. But we can leverage thecopyaction on the text field that is associated with the menu controller. Thecopyaction copies the text onto the pasteboard which we will need to retrieve. I was able to implement aLogfunction in my custom subclass ofUITextFieldlike this –This logs the selected text onto the console. Doesn’t do much but gives you the basic idea.