gpt4 book ai didi

objective-c - NSTokenField 点击完成列表项

转载 作者:搜寻专家 更新时间:2023-10-30 20:02:54 24 4
gpt4 key购买 nike

我的应用程序中有一个 NSTokenField 并且我实现了 tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: 方法,在该方法中我使用 setTokenizingCharacterSet: 方法:

  def tokenField(tokenField, completionsForSubstring:substring, indexOfToken:tokenIndex, indexOfSelectedItem:selectedIndex)
tokenField.setTokenizingCharacterSet(NSCharacterSet.whitespaceAndNewlineCharacterSet)
end

当我单击空格键或回车按钮时,它按预期工作。当我用鼠标单击完成列表中的一项时,我也希望有相同的行为。

这怎么可能?

感谢您的帮助。

最佳答案

我不知道 NSTokenField 是否可以实现这种行为。

但是你应该看看MTTokenField开箱即用。

为此,您必须:

1.创建一个 Xcode 项目作为静态库(不启用 ARC)。

2.将你的项目保存到vendor/MTTokenField

3.将位于“MTTokenField”子目录中的 MTTokenField 的所有文件拖放到您的新 XCode 项目中。选择复制文件。

4.将其添加到您的 rakefile 中,以便编译该库并将其与您的 Rubymotion 项目链接。

app.vendor_project("vendor/MTTokenField/", :xcode, :xcodeproj => "MTTokenField.xcodeproj", :target => "MTTokenField", :products => ["libMTTokenField.a"], :headers_dir => "MTTokenField")

5.在 Interface Builder 中,将 NSTokenField 的类更改为 NSTextField,然后将其自定义类设置为 MTTokenField,同时更改单元格的自定义类:MTTokenFieldCell 而不是 NSTextFieldCell。

6.然后您必须将 MTTokenField 的委托(delegate)设置为必须响应的类:

def tokenField(tokenField, completionsForSubstring: substring )
# your have to return an array containing your results matching substring.
end

就是这样。它应该有效。

希望对您有所帮助!

关于objective-c - NSTokenField 点击完成列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17230822/

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