Cliff Ribaudo Cliff Ribaudo - 4 months ago 20x
Objective-C Question

NSTextField not noticing lost focus on NSWindow close

I have several NSTextField that are used on a dialog created as an NSWindow and which is displayed via:

[NSApp runModalForWindow:dialog]

My problem is that if a user clicks in the
, edits the value and then clicks the dialogs DONE button which closes the dialog via:

[NSApp stopModal]

doesn't get any of the delegate methods indicating editing will end or has ended and the value is not persisted.
I would rather not persist the values continuously in:


I'm not clear why if the NSTextField has firstResponder status given that it is being edited, and then loses it, why it doesn't get any delegate methods. Is there some other way to detect this.


What fixed this was changing this:

[self resignFirstResponder];

to this:

[self makeFirstResponder:nil];

By doing that the text field on the modal window that currently had focus got the message. I'm not sure why resignFirstResponder doesn't work but setting it to nil doe, but there you have it.