I was doing some experimentation this week. Someone recommended a feature in my soon to be released disc image dictionary attack tool.
I display the file path in an NSTextField. And it is possible that path could end up longer than the field displays. So they recommended I populate the Tool Tip popup with the contents of the text field.
I found that took two things in my case.
First I had to make the Tool Tip populate when a user selected the file from the open dialog box. That is easy enough. We just call setToolTip method for the TextField.
[projectPathField setToolTip:[self filePath]];
Now the tricky part. That sets the tool tip when I first get the filePath. But now if the field is editable you want the tool tip to keep up with the contents of the field. I added the following method with one line of code to my AppController class. Then I just made sure to set my AppController object as Delegate of the NSTextField in Interface Builder. Now the tool tip stays in sync as someone types in the text field.
– (void)controlTextDidChange:(NSNotification *)aNotification
[[aNotification object] setToolTip:[[aNotification object] stringValue]];