首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSTokenField自动完成

NSTokenField自动完成
EN

Stack Overflow用户
提问于 2010-01-16 23:47:40
回答 1查看 2K关注 0票数 0

我正在创建一个使用NSTokenField的应用程序。我需要自动补全。我正在使用NSURLRequest从http://stackoverflow.com/filter/tags?_=<timestamp>&limit=6&q=<str_to_autocomplete>&timestamp=<timestamp>请求数据

其中<timestamp>是当前时间戳,<str_to_autocomplete>是要自动完成的字符串。所以,例如http://stackoverflow.com/filter/tags?_=1263657227137&q=lol&limit=6&timestamp=1263657227137

响应的格式如下:

代码语言:javascript
复制
javascript|23179
jquery|16936
sql-server|11768
ruby-on-rails|8669
best-practices|7037
ruby|6722

(该数字是使用此标记的次数)。

我需要在NSTokenField下为用户提供一个列表,其中包含此标记列表,用户可以选择其中一个列表,也可以继续键入。

有谁可以帮我?谢谢。

编辑:我现在看的是Mac Dev Center。我应该使用这个方法:tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-01-22 00:27:09

这将被发送给委托以查询字符串数组:

代码语言:javascript
复制
tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: 

然后,这些字符串应该由representedObject中的tokenField处理(如果只需要字符串,则不需要)。

tokenField委托中的示例:

代码语言:javascript
复制
- (NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex
{
    //code to find the tags strings corresponding to substring (the string typed in the token)
    //then put them in an array (returnArray)
    return returnArray;
}

当您键入时,tokenField将在菜单中显示完成的字符串。所有细节都在文档中。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2077914

复制
相关文章

相似问题

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