1

I have an iOS keyboard question.

Say we have a UITextField (let's call it textfield) and a standard virtual keyboard, with the Enter key set to Send. We'd like to disable the Send key when UITextField is empty, otherwise enable it. We have set enablesReturnKeyAutomatically to YES on the text field. This works fine when we manually edit the text in the text field.

However, the Send key doesn't seem to work fine when we programmatically change the text. Our app will clear the text field by calling textfield.text = @"" once the Send key is hit and the text is sent. In this case, we expect the Send key to be disabled since textfield's content is empty. But no -- it appears enabled.

We want to disable the Send key in such a case. Please share your experience if possible.

Thanks!

lgc_ustc
  • 1,524
  • 2
  • 20
  • 31

1 Answers1

1

I think the best you can do is to ignore the return event this way:

- (BOOL) textFieldShouldReturn:(UITextField*) textField {
    return textField.text.length > 0;
}
alex
  • 8,904
  • 6
  • 49
  • 75
  • Is setReturnKeyEnabled a public method? This link says it's not: http://stackoverflow.com/questions/788323/disable-enable-return-key-in-uitextfield. If it's not, we still prefer a solution with a public method. – lgc_ustc Nov 09 '14 at 09:39
  • Doesn't seem to work though. The Send button still appears enabled. – lgc_ustc Nov 09 '14 at 09:55
  • Yes i believe you have no chance to disable it using ios SDK only. – alex Nov 09 '14 at 10:12