如何在显示另一个属性字符串的同时将NSTextField绑定到原始字符串? [英] How to bind a NSTextField to a raw string while displaying another attributed string?

查看:242
本文介绍了如何在显示另一个属性字符串的同时将NSTextField绑定到原始字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用基于视图的 NSTableView ,并希望允许用户编辑文本。 Cocoa通常对此有很好的支持,但我不知道如何将 NSTextField 的值绑定到一个字符串,同时向用户显示稍微不同的字符串,如下所示。例如,当用户单击文本字段或按Enter键进行编辑时,字段编辑器只能使用 exportTest.zip 而不是 exportTest .zip Shared ,无论编辑用户做什么都应该只影响 exportTest.zip 值。可以使用可可文本吗?

I'm using view-based NSTableView and would like to allow users to edit text in place. Cocoa typically has superb support for this, but I am not sure how to bind the value of NSTextField to one string while displaying a slightly different string to the user, as shown below. For example, when user clicks on a text field or presses enter key to edit, the field editor should only be filled with exportTest.zip and not exportTest.zip Shared, and whatever edit user makes should only affect the exportTest.zip value as well. Can this be done using cocoa text?

推荐答案

这可以很容易地用NSFormatter做,但是为了防止任何人像我一样努力,指出,为了在编辑时显示不同的字符串,您需要覆盖 editingStringForObjectValue:

This can easily be done with NSFormatter however just in case anyone else struggles as I did I thought I'd point out that in order to display a different string when editing you will need to override editingStringForObjectValue:

这篇关于如何在显示另一个属性字符串的同时将NSTextField绑定到原始字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆