How can I call some code upon entering a UITextView (user taps to edit it) and leaving the view (user taps to leave it)?
Appreciate any help.
How can I call some code upon entering a UITextView (user taps to edit it) and leaving the view (user taps to leave it)?
Appreciate any help.
You could also implement the UITextViewDidChange delegate methods. I use the code below in my app for taking quick notes. Whenever the user has entered a character, the observer catches this from the notification center and calls the saveText method.
Here's how:
Add this line to the viewDidLoad method:
and these lines at the appropriate place in your code (like in the section that handles the text view delegate methods. TIP: Use pragma marks for this (#pragma mark - TextView Delegate Methods):
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html#//apple_ref/occ/intf/UITextViewDelegate
Here you can find several useful methods to investigate:
textViewDidBeginEditing:
textViewDidEndEditing:
Moreover to live
UITextView
you often should implement action that calls[yourTextView resignFirstResponder];
Objective-C example
Swift Example
use the delegate and use: