首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在*编辑过程中替换NSTextFieldCell *的内容?

在*编辑过程中替换NSTextFieldCell *的内容?
EN

Stack Overflow用户
提问于 2013-07-16 17:54:37
回答 1查看 630关注 0票数 3

如果用户在编辑时输入了某些文本,我将尝试用粗体显示NSTextFieldCell的内容。

到目前为止我已经知道了:

在awakeFromNib中:

代码语言:javascript
复制
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldCellDidChange:)  name:NSControlTextDidChangeNotification object:theNSTableView];

方法:

代码语言:javascript
复制
- (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内容?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-17 16:32:45

要在进行更改后获得NSTextFieldCell的stringValue,请将NSTextFieldCell子类实现如下:

代码语言:javascript
复制
- (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) ;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17683694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档