Mail.app 类似 NSTokenField 用于姓名和电子邮件
我想构建一个 NSTokenField ,其工作方式就像 Mail.app 中的收件人字段一样。我知道如何在地址簿中搜索姓名和电子邮件。这些可能是非常糟糕的菜鸟问题,对此感到抱歉。
如何重新格式化搜索结果数组以获取格式为“姓名 <电子邮件>”的项目(如 Mail.app 中的自动完成结果)
NSTokenField Completion 方法如何工作?我找不到适合我的代码示例。你能解释一下或者给我一些代码吗?
I want to build a NSTokenField that works just like the recipient field in Mail.app. I know how to search the address book for names and emails. These are probably really bad noob questions, sorry for that.
How can I reformat my search results array to get items in the format "Name <email>" (like the auto completion results in Mail.app)
How does the NSTokenField Completion method work? I can't find a code example that works for me. Can you explain it or give me some code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经有一段时间没有使用 NSTokenField 但这里是:
Ad。 2.您有一个名为
tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:
的 NSTokenField 委托方法,它应该返回提供的子字符串的可能竞争数组。它的工作方式是,您将类设置为 NSTokenField 的委托并重写该方法,并在其中搜索数据库中与提供的子字符串匹配的记录,并返回可能匹配的数组。剩下的就应该由可可来做。广告。 1. NSTokenField 委托再次可以具有名为 tokenField:displayStringForRepresentedObject: 的方法,该方法允许您以任何您想要的格式显示某些对象(例如电子邮件地址)(因此该对象将只是电子邮件,您可以通过在数据库中查找该特定电子邮件的名称来从该方法返回格式为“名称”的字符串)。
希望有帮助!
It's been a while since I used NSTokenField but here it goes:
Ad. 2. you have a method of NSTokenField delegate called
tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:
which should return an array of possible competitions of provided substring. The way it works is that you set your class as a delegate of your NSTokenField and override that method and in it you search your database for records that matches provided substring and return an array of possible matches. The cocoa should do the rest.Ad. 1. once again
NSTokenField
delegate can have method calledtokenField:displayStringForRepresentedObject:
which allows you to display the some object (like email address) with any format you want (so the object would be just email and you might return string in a format "Name " from that method by finding name for that particular email in your database).Hope that helps!