View Full Version : endEditingFor:nil

Jul 13, 2009, 11:48 PM
I am sure there is a simple answer, but I have not seen it anywhere.

In Hillegass, the method
- (NSData *)dataOfType: (NSString *)typeName error: (NSError **)outError

is edited to archive the document.

One of the calls to stop all editing is:
[[ tableView window] endEditingFor: nil];

The documentation says of the argument for "endEditingFor" The object that is using the window’s field editor

Could anyone help me understand then why "nil" is provided as an argument, when it is supposed to be directed at an object using the field editor...in other words...what objects are supposed to be receiving this message. It obviously works, but I am just trying to figure out why.

Thanks as always.

Jul 15, 2009, 12:45 PM
Taken from: http://discussions.apple.com/thread.jspa?messageID=9825472

When thisObject is valid and using the field editor, the field editor is forced to resign first responder status, send textDidEndEditing: to its delegate and disassociate from thisObject. When thisObject is nil, if the field editor is first responder, it must similarly resign and end editing regardless of which object it's associated with.

An object might send endEditingFor:self when finished editing in a case where no other object has asked to become first responder. The window controller might send endEditingFor:nil if the first responder needs to change but the field editor refuses to give up first responder (for example because the current text is invalid). AFAIK, if myObject is the object with the field editor, endEditingFor:myObject does the same thing as endEditingFor:nil. Passing nil just saves the caller from trying to find out which object, if any, has the field editor.