I have simple NSSearchField on view of NSVIewConroller. and connected the NSSearchFIeld's delegate to the view controller. And I have implemented the NSSearcHFieldDelegate Methods as follows:
- (void)searchFieldDidStartSearching:(NSSearchField *)sender NS_AVAILABLE_MAC(10_11);
{
NSLog(@"search field did start: %@", sender.stringValue);
}
- (void)searchFieldDidEndSearching:(NSSearchField *)sender NS_AVAILABLE_MAC(10_11);
{
NSLog(@"search field did end: %@", sender.stringValue);
}
These methods are not getting called on start editing and end editing. But If I implement the NSControl default delegates like controlTextDidChange: and control:textShouldBeginEditing: are called on respective events.
Why the NSSearchFieldDelegate methods are not called?..
Step 1: Your controller class needs to inherit from NSSearchFieldDelegate
Step 2: Implement the below 2 methods
Step 3: in the viewDidLoad, windowDidLoad, awakeFromNib etc set the delegate for the search field as the view controller/ window controller etc
A working sample is as below