如果在编辑NSTextFieldCell时用户输入了某些文本,我正在尝试用粗体显示NSTextFieldCell的内容。
到目前为止,我已经得到了这个:
在awakeFromNib中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldCellDidChange:) name:NSControlTextDidChangeNotification object:theNSTableView];
方法:
- (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];
}
在编辑过程中是否可以捕获NSTextFieldCell的编辑内容?
答案 0 :(得分:2)
要在更改后获取NSTextFieldCell的stringValue,请将NSTextFieldCell子类化并实现:
- (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) ;
}