gpt4 book ai didi

cocoa - *在*编辑期间替换 NSTextFieldCell 的内容?

转载 作者:行者123 更新时间:2023-12-03 16:20:20 26 4
gpt4 key购买 nike

如果用户在编辑 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 的已编辑内容?

最佳答案

要在更改后获取 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) ;
}

关于cocoa - *在*编辑期间替换 NSTextFieldCell 的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17683694/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com