Re: How to make key shortcuts and mouse click trigger controlTextDidEndEditing:
Re: How to make key shortcuts and mouse click trigger controlTextDidEndEditing:
- Subject: Re: How to make key shortcuts and mouse click trigger controlTextDidEndEditing:
- From: "Erik M. Buck" <email@hidden>
- Date: Sat, 5 Mar 2005 16:50:51 -0500
This is a variant of a FAQ. Please see the archives:
http://www.cocoabuilder.com/archive/message/2004/11/15/121675
In whatever action method is called by your menu items or other controls,
call the following code taken directly from Apple's documentation:
if ([myWindow makeFirstResponder:myWindow]) {
// All fields are now valid; it's safe to use fieldEditor:forObject: to
claim the field editor.
}
else
{ // Force first responder to resign.
[myWindow endEditingFor:nil];
}
See also: - fieldEditor:forObject:, - windowWillReturnFieldEditor:toObject:
You can call this at the start of your document saving code to finalize the
editing of any field that might have the user's focus.
>From Apple's Documentation:
endEditingFor:
- (void)endEditingFor:(id)anObject
Forces the field editor, which anObject is assumed to be using, to give up
its first responder status, and prepares it for its next assignment. If the
field editor is the first responder, it's made to resign that status even if
its resignFirstResponder method returns NO. This forces the field editor to
send a textDidEndEditing: message to its delegate. The field editor is then
removed from the view hierarchy, its delegate is set to nil, and it's
emptied
of any text it may contain.
This method is typically invoked by the object using the field editor when
it's finished. Other objects normally change the first responder by simply
using makeFirstResponder:, which allows a field editor or other object to
retain its first responder status if, for example, the user has entered an
invalid value. The endEditingFor: method should be used only as a last
resort
if the field editor refuses to resign first responder status. Even in this
case, you should always allow the field editor a chance to validate its text
and take whatever other action it needs first. You can do this by first
trying to make the NSWindow the first responder:
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden