1

I hava a UITextView ,and after some characters' input, I want to use a button click to hide the keyboard and the UITextView is still in focus....[Attention:the button is not a return key or a done key];

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
matrix1024
  • 27
  • 1
  • 8

2 Answers2

0

Have you set delegate to your UITextView instance? If so, try using [_textView resignFirstResponder];

else

Try using [self.view endEditing:YES];

Ananth
  • 815
  • 9
  • 26
  • 1
    Hello,I just try resignFirstResponder,but found that the UitextView lost focus,how about [self.view endEditing:YES]; what's that mean? – matrix1024 Jun 15 '12 at 10:05
  • Sorry, I don't understand what you mean as "lost focus". [self.view endEditing:YES] makes all the views that are under editing (i.e tableview, textview and textfield) to non-editing state. – Ananth Jun 15 '12 at 10:11
  • He wants to say that textfield is still in editing mode ie focused the curs-sure is in textfield and blinking but the keyboard is hidden – The iOSDev Jun 15 '12 at 10:16
  • @AalokParikh, thanks for your explanation. Its seems something wiered. – Ananth Jun 15 '12 at 10:37
  • 1
    Have a look at this link http://stackoverflow.com/a/8350573/1424174 . Is this similar to your case? – Ananth Jun 15 '12 at 10:38
0

mplement following code to your view controller .m file & .h file add delegate of textView

 -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
  if([text isEqualToString:@"\n"])
    [textView resignFirstResponder];
  return YES;
}

Now goto interface builder, select your textview & set return key type done.

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • the button is not a return key or a done key,the button click will show a menu,then click a menu item like"UserName" then i can add a string like "jake" to the uitextview – matrix1024 Jun 15 '12 at 10:13