0
votes

My NSDocument subclass adopts NSTextFieldDelegate. The document window contains several NSTextField instances (all setup as outlets of the document class). When the user edits a text field, I want my document to be notified. But all the methods in the NSTextFieldDelegate protocol are inherited from NSTextViewDelegate and hence pass NSText* instances in their parameters, NOT NSTextField instances. The same applies to the notification:

- (void) controlTextDidChange:(NSNotification*) notification

So, How do I find out which of the many NSTextField instances is being edited?

NOTE

I need to register undos properly, using the document's undo manager. I tried implementing - (NSUndoManager *)undoManagerForTextView:(NSTextView *)aTextView but this seems to only work with NSTextViews, NOT NSTextFields.

1

1 Answers

3
votes

You can get a reference to your NSTextField as [notification object]. From the documentation for NSControlTextDidChangeNotification:

The notification object is the NSControl object posting the notification.

The actual control subclass will be your NSTextField.