UITextView adding new line unintentionally?

前端 未结 3 825
别跟我提以往
别跟我提以往 2020-12-03 09:31

I have a scroll view which contains a UITextField and a UITextView. The UITextField return key is \"Next\" and when this is pressed I call [myTextView becomeFirstResponder];

3条回答
  •  不思量自难忘°
    2020-12-03 10:37

    Okay, this behaviour is due to a bug in iOS when becoming firstresponder within same run loop by using next button. To over come this you should do this manually. First resign first responder from a textFied, and then make textView as a first responder. like this. Implement this delegate method.

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        [textField resignFirstResponder];
        [textView performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
        return YES;
    }
    

提交回复
热议问题