Assign Method to didEndOnExit UITextField Event

How to programmatically assign a method (observer?) For the didEndOnExit event of a didEndOnExit object?

This is easy enough to do in IB, but I can't figure out how to do this in code.

+6
iphone cocoa-touch uitextfield
source share
3 answers

I just got it ...

 [mytextField addTarget:self action:@selector(methodToFire:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
+30
source share

In your view, the controller implements the following method:

 - (void)textFieldDidEndEditing:(UITextField *)textField{ //do stuff } 

Remember to set the delegate to viewDidLoad or the initializer:

 myTextField.delegate = self; 
+4
source share

For those who choose to use this goal so that another text field becomes the FirstResponder to create a "Next" button, which seems like you are "tabbing" through textFields, I would recommend using textFieldShouldReturn with this code instead. Let me tell you that it works so well that you will feel like riding a unicorn:

  -(BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; if([textField isEqual:_textField1]){ [_textField2 becomeFirstResponder]; return NO; }else if([textField isEqual:_textField2]){ [_textField3 becomeFirstResponder]; return NO; } return YES; } 
+1
source share

All Articles