Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textFieldShouldReturn method of UITextview

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?

like image 751
learner Avatar asked Aug 24 '14 15:08

learner


1 Answers

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

like image 200
Jim Tierney Avatar answered Sep 25 '22 00:09

Jim Tierney