如果用户在编辑时输入了某些文本,我将尝试用粗体显示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内容?
发布于 2013-07-17 16:32:45
要在进行更改后获得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) ;
}https://stackoverflow.com/questions/17683694
复制相似问题