2

I would like to enable the keyboard return key only when some uitextfields are not empty. I read this question How to disable/enable the return key in a UITextField?

Is this the only way? Is it true this could cause Apple to reject the app?

Community
  • 1
  • 1
Sefran2
  • 3,578
  • 13
  • 71
  • 106

3 Answers3

3

Following thing will enable/disable return key automatically.

  • (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

     textfield.enablesReturnKeyAutomatically = YES;
    
    // your code here
    
      return YES;  }
    
Gaurav
  • 8,227
  • 4
  • 34
  • 55
0

This is not a public API, so use it on your own risk.

textField.setValue(true/false, forKeyPath: "inputDelegate.returnKeyEnabled")

More detailed answer here.

Paul B
  • 3,989
  • 33
  • 46
-1

You can use the textFieldShouldReturn: method to prevent the return key from returning.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html

GendoIkari
  • 11,734
  • 6
  • 62
  • 104
  • Sorry, I mean that I would the keyboard return key "disactive" if there aren't particular conditions. Using textFieldShouldReturn: I prevent the return key from returning... I would that it was visually disabled. – Sefran2 Mar 02 '11 at 18:27
  • I figured that that's what you meant; but using that method could at least be a work-around if there is no way to actually disable the button. – GendoIkari Mar 02 '11 at 19:30
  • Yes, I have not explained well. Thanks for the suggestion. – Sefran2 Mar 03 '11 at 14:23