I have a UITextView which I am using as text entry in a translation application. When the user presses return/search then I want to do some action e.g. searching for word from textView. I want to do some action like we do with IBAction.
Set up delegate of the textView. Than add shouldChangeTextInRange for detecting of the return/search buttons and performAction for you're custom action.
override func viewDidLoad() {
super.viewDidLoad()
self.textView.delegate = self
}
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
if (text == "\n") {
textView.resignFirstResponder()
performAction()
}
return true
}
func performAction() {
}
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