我正在创建一个使用NSTokenField的应用程序。我需要自动补全。我正在使用NSURLRequest从http://stackoverflow.com/filter/tags?_=<timestamp>&limit=6&q=<str_to_autocomplete>×tamp=<timestamp>请求数据
其中<timestamp>是当前时间戳,<str_to_autocomplete>是要自动完成的字符串。所以,例如http://stackoverflow.com/filter/tags?_=1263657227137&q=lol&limit=6×tamp=1263657227137
响应的格式如下:
javascript|23179
jquery|16936
sql-server|11768
ruby-on-rails|8669
best-practices|7037
ruby|6722(该数字是使用此标记的次数)。
我需要在NSTokenField下为用户提供一个列表,其中包含此标记列表,用户可以选择其中一个列表,也可以继续键入。
有谁可以帮我?谢谢。
编辑:我现在看的是Mac Dev Center。我应该使用这个方法:tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:吗?
发布于 2010-01-22 00:27:09
这将被发送给委托以查询字符串数组:
tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: 然后,这些字符串应该由representedObject中的tokenField处理(如果只需要字符串,则不需要)。
tokenField委托中的示例:
- (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将在菜单中显示完成的字符串。所有细节都在文档中。
https://stackoverflow.com/questions/2077914
复制相似问题