iPhone Objective-C: Keyboard won't hide with resignFirstResponder, sometimes

前端 未结 1 1968
自闭症患者
自闭症患者 2021-01-27 01:34

I have a UITextView which I call resignFirstResponder on when the return key is hit. The text view does resign first responder (the flashing cursor thing in the text bo

相关标签:
1条回答
  • 2021-01-27 02:04

    Declare the UITextViewDelegate protocol

    Then implement this

    -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
     if([text isEqualToString:@"\n"])
    {
            [textView resignFirstResponder];
            return NO;
    }
    
        return YES;
    }
    
    0 讨论(0)
提交回复
热议问题