ios - How to make a button default programmatically in Xcode? -


I have a small iOS app and I need to execute the button action when the user presses 'Enter'.

I have found this in the apple developer site

And my question is where should I enter this

  [myButton setKeyEquivalent: @ "\ r"];  

Try something like this:

  1. Set the self (current UIViewController) as the representative for your example of UITextField or UITextView:

      self.myTextField.delegate = self;  
  2. In your controller @interface the protocol & lt; UITextFieldDelegate & gt; Do not forget to implement . / P>

  3. Then apply those methods:

      - (BOOL) textFieldShouldReturn: (UITextField *) Textfield {[self.myButton performSelector: @selector (MyButtonClicked object with: self.mybutton]; Yes come back } - (IBAction) myButtonClicked: (ID) sender {NSLog (@ "myButton clicked"); }  

Comments