0 cocoa parsing autocomplete objective-c nstokenfield
我正在创建一个使用NSTokenField的应用程序.我需要自动完成.我正在使用NSURLRequest来请求数据http://stackoverflow.com/filter/tags?_=<timestamp>&limit=6&q=<str_to_autocomplete>×tamp=<timestamp>
<timestamp>当前时间戳在哪里,a <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
Run Code Online (Sandbox Code Playgroud)
(该数字是此标记的使用次数).
我需要在NSTokenField下为用户提供一个带有此标记列表的列表,用户可以选择其中一个列表,也可以继续输入.
谁能帮我?谢谢.
编辑:我现在正在看Mac Dev Center.我应该使用此方法:tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:?
小智 5
这将发送给委托以查询字符串数组:
tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem:
Run Code Online (Sandbox Code Playgroud)
然后应该由tokenFieldin 处理这些字符串representedObject(如果只需要字符串,则不会处理).
代理中的示例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;
}
Run Code Online (Sandbox Code Playgroud)
tokenField在您键入时,将显示菜单中完成的字符串.所有细节都在文档中.
| 归档时间: |
|
| 查看次数: |
1883 次 |
| 最近记录: |