0

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

<timestamp>当前时间戳在哪里,an<str_to_autocomplete>是要自动完成的字符串。所以,例如http://stackoverflow.com/filter/tags?_=1263657227137&q=lol&limit=6&timestamp=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:

4

1 回答 1

5

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

tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: 

然后应该由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;
}

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

于 2010-01-21T16:27:08.937 回答