Set delegate for UITextView.
First declare a delegate:
@interface YourViewController ()<UITextFieldDelegate>
Second set for self
self.textView.delegate = self;
Use this method:
-(void)textViewShouldReturn:(UITextField *)textField { if ([textField.text isEqualToString:@""]){ return; } UIAlertView *helloEarthInputAlert = [[UIAlertView alloc] initWithTitle:@"Name!" message:[NSString stringWithFormat:@"Message: %@", textField.text] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
To add a property, write the following code in the h file:
@property (weak, nonatomic) IBOutlet UITextView *textView;
To connect this text box, go to the storyboard and click on the controller of your kind. Then go to the connection inspector (all the way to the right). Under the exits, drag the circle next to the textView into your text file.
source share