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 NSTextField , edits the value and then clicks the dialogs DONE button which closes the dialog via:

[NSApp stopModal]

The NSTextField 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:

controlTextDidChange:aNotification

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.

链接地址: http://www.djcxy.com/p/85256.html

上一篇: 如何将几个NSTextField绑定到xib中的NSMutableDictionary的条目?

下一篇: NSTextField没有注意到失去对NSWindow关闭的重点