views:

22

answers:

1

So I know you have to put this in the .h file:

- (void)textDidEndEditing:(NSNotification *)aNotification

BUT what do I call in the .m file?? How do I show that text is done editing in one of several NSTextFields?

I looked around on the internet, but it seems pretty vague on how to use it correctly.

Any ideas? Elijah

A: 

Take a look at UITextFieldDelegate. It will give you the method callbacks you want, such as textfieldDidEndEditing. It should pass the text field which you can then identify by object comparison or tag value.

UPDATE

Code sample for the delegate callback. Be sure to add UITextFieldDelegate to your .h file. Also specific your textField's delegate property, textField.delegate = self in your code or in IB.

- (void)textFieldDidEndEditing:(UITextField *)textField {
  if (textField.returnKeyType == UIReturnKeyDone) {
    // the textfield with the Done return key is what I care about
    self.value2 = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  }
}
Jason McCreary
Can you show a quick example? If not no prob!
Elijah W.
Of which part: Delegate or the method?
Jason McCreary
See above. Hopefully that get's you started.
Jason McCreary
Note that the poster is asking about NSTextField, not UITextField. Not that it necessarily changes the answer much, but Cocoa and Cocoa Touch aren't always identical.
Chris Hanson