Needing to present user a multiline text field for comment entry, I am using a UITextView instead of a UITextField. I would like to use textFieldShouldReturn
on my UITextView to send the data to server. How might I do that? Based on my readings so far, the method is only applicable to UITextField. So what is the equivalent for UITextView?
By adding the UITextViewDelegate to your viewControllerHeader
@interface ViewController : UIViewController<UITextViewDelegate>
This'll allow you access to the UITextViewDelegate methods of which there are a couple of which should allow you to know when the user has either pressed return or let you know when they have finished editing, for example
- (void)textViewDidEndEditing:(UITextView *)textView{
//From here you can action your methods to send the data to your server as required etc.
}
There's also this method
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
//Which you can use to listen for the @"\" return action if you prefer.
}
I hope this helps
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