0

Hey I got a problem with a tutorial I found for autocompletion: It says -

Now, when the text in the text field has changed (ie: in the EditingChanged handler), just call the GetSuggestions method, which will return an array of strings that match the parameter passed

NSArray *suggestions = [autocomplete GetSuggestions:textField.text];

You can do whatever you want with these suggestions, I displayed them in a table view and when the user taps a cell, the text is added to the text field (source)

Well I placed the array in

...textField:(UITextField *)textField shouldChangeCharactersInRange...

but I cannot figure out how to 'call' the suggestions when I write something right behind my text somewhat like autocorrection :/ any thoughts?

tried something like

if ([textField.text length] > 0){
        ..somehow call suggestions

    }

but that just doesn't work :P

4

1 回答 1

0

您需要创建一个视图来显示它们。到目前为止,您所做的只是将自动完成建议加载到一个数组中。

您需要在 TableView 或其他内容中显示它们。看这里以获得关于它们如何工作的好教程。-> http://www.youtube.com/watch?v=_Qbjwx0hB6A&list=SPE83F832121568D36&index=13

好好看看作者提供的源代码,他演示了他是如何使用数组来填充一个TableView的。

编辑:youtube 教程是针对 OS X 编程的 NSTableView 的,但你掌握了它的窍门。

于 2013-03-25T23:10:50.560 回答