NSTextView, where is it coming from when using NSSearchField and NSTextField

841 Views Asked by At

Where does NSTextView come from?

In my OSX application i have a NSSearchField, i implemented controlTextDidChange: which contains in key NSFieldEditor a NSTextView instance

- (void)controlTextDidChange:(NSNotification *)note {

    NSTextView * searchField = note.userInfo[@"NSFieldEditor"];
    ...
}

also when asking

id firstResponder = [self.window firstResponder];

i get a NSTextView

But where is it coming from??? as NSSearchField nor NSTextField is NOT derived from NSTextView... also not it's cell... also i cannot find a property for it in NSSearchField

I'am using NSSearchField for sure

enter image description here

also when connecting the action outlet to NSSearchField, the sender is NSSearchField (which is ok)

- (IBAction)searchFieldCommit:(NSSearchField *)sender {
   //...
}

What is this mess, why do i get NSSearchField vs NSTextView and how to access the NSSearchField from NSTextView and vice versa

2

There are 2 best solutions below

0
On

Cocoa maintains a shared NSTextView called the "field editor". It is described in more detail here:

https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextFieldsAndViews/TextFieldsAndViews.html

0
On

Aderstedt is right about the field editor. The other thing you need to know is that in your controlTextDidChange: method, note.object will be the control that sent the notification.