Detecting lost focus for NSTableView in Cocoa

cocoa

Solution

You can do this in 10.6 and later by using KVO to observe the window's `firstResponder`. It will change when the focused control in the window changes.

Put the code you want to run in the observing object's `observeValueForKeyPath:ofObject:change:context:` method.

Problem

Is there any way to detect and respond when a control on a window loses focus? I want to run some code when a user leaves NSTableView. Thanks,

Original source