gpt4 book ai didi

swift - 停止 NSTokenField 修剪空格

转载 作者:行者123 更新时间:2023-11-28 15:34:06 24 4
gpt4 key购买 nike

我试图将 stringValue 设置为 NSTokenField(NSTextField 的子类),但我发现如果字符串以空格开头,它会删除它。我想保留空间。我也尝试过应用格式化程序,但没有成功。即:

tokenField.stringValue = " 1"

这实际上会在字段中读出“1”。

此外,我想格式化一个整数,但还要在它之前保留零。即:

    tokenField.stringValue = "001"

这也将在字段中读出“1”。

我试过重写各种函数,但没有成功。有什么想法吗?

谢谢!

最佳答案

来自 the documentation of NSTokenField :

In OS X v10.4, NSTokenField trims whitespace around tokens but it does not trim whitespace in macOS versions 10.5.0 and 10.5.1. In OS X v10.5.2, you get whitespace-trimming behavior by either linking against the v10.4 binary or linking against the v10.5 binary and not implementing the tokenField(_:representedObjectForEditing:) method. If you do not want the whitespace-trimming behavior, link against the v10.5 binary and implement this method, returning the editing string if you have no represented object.

好吧,它有点旧,方法的名称不正确,但它说:

If you do not want the whitespace-trimming behavior, implement tokenField(_:representedObjectForEditingString:), returning the editing string if you have no represented object.

关于swift - 停止 NSTokenField 修剪空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44477845/

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