how to resign keyBoard as a firstResponder from a textView?

前端 未结 4 1022
梦谈多话
梦谈多话 2021-01-25 03:01

I want to resign the keyboard from the text view as a first responder.I want as soon as user hits the return key after editing in a textView the keyboard should resign.But I am

4条回答
  •  感情败类
    2021-01-25 03:09

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

    yourTextView.delegate=self; Also add, in '.h' file

    If you didn't add "if([text isEqualToString:@"\n"])" you can't edit

提交回复
热议问题