Reputation: 5142
I'm trying to boldface the contents of an NSTextFieldCell if certain text is entered by the user while the NSTextFieldCell is being edited.
So far I've got this:
In awakeFromNib:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldCellDidChange:) name:NSControlTextDidChangeNotification object:theNSTableView];
The method:
- (void) textFieldCellDidChange: (id) sender
{
//successfully captures contents of the NSTextFieldCell prior to the
//start of editing
NSString * textOfMyNSTextFieldCell = [myNSTextFieldCell stringValue];
//attempts to capture the current edited contents of the NSTextFieldCell while
//editing is still in progress:
//but DOES NOT YET WORK:
NSText *fieldEditor = [myTableView currentEditor];
textOfMyNSTextFieldCell = [fieldEditor string];
}
Is it possible to capture the edited contents of an NSTextFieldCell while editing is still in progress?
Upvotes: 3
Views: 652
Reputation: 4421
To get the NSTextFieldCell's stringValue after a change is made, subclass NSTextFieldCell and implement this:
- (void) textDidChange:(NSNotification*)notification {
NSLog(@"NSTextFieldCell noticed that text did change to: %@", self.stringValue) ;
NSLog(@"Was notified by: \n%@", notification.object) ;
NSLog(@"which is its controlView's currentEditor: \n%@", ((NSTextField*)self.controlView).currentEditor) ;
}
Upvotes: 2