robject
robject

Reputation: 808

How to force an NSTextField to accept the text?

I have an NSTextField in a Preferences panel. It provides a field to enter a url in. However, if the user closes the Preferences panel after editing the text in the field, the new value does not get propagated to the User Defaults. This only happens after the user explicitly does Enter or Tab.
This kind of makes the whole approach useless, it seems to me, so I guess I must be doing something wrong?

Upvotes: 1

Views: 177

Answers (1)

Nathan Kinsinger
Nathan Kinsinger

Reputation: 25021

I fix this by setting the firstResponder to nil when the window closes.

[[self window] makeFirstResponder:nil];

Upvotes: 2

Related Questions