This is a migrated thread and some comments may be shown as answers.

Identifying the selected item when autocomplete

3 Answers 78 Views
AutoCompleteTextView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Karl
Top achievements
Rank 1
Karl asked on 01 Feb 2016, 10:19 PM

Hi there.

I have set up a sample autocomplete view controller inside one of my projects. The _dataSource is an array of NSManagedObjects and the type ahead completion etc works just fine. Of course, having found my item in the long list I would like to do something with it. I can't see anything in the example project that lets me identify the selection I have made. I have the delegate working and the following does fire. It displays the correct text description of the item.

- (void)autoComplete:(TKAutoCompleteTextView *__nonnull)autocomplete didAutoComplete:(NSString * _Nonnull)completion {
    NSLog(@"Selected : %@",completion);
}

Where do look to find the selected item? Ideally, this would be the id of the item I selected but I could live with its key. 

3 Answers, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 04 Feb 2016, 04:23 PM
Hello, Karl,

Thank you for contacting us.

The method you are implementing is correct. Having the selected string you should be able to get the item from your dataSource. It would be great if you could send me a sample project, so I can give you proper solution.

I am looking forward to your reply.

Regards,
Adrian
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Karl
Top achievements
Rank 1
answered on 04 Feb 2016, 04:50 PM

Hi Adrian,

Thank you for your reply. 

I have the string but what I don't have is the link back to the object that the string came from. My original data source already stands at 800 NSManagedObjects. It seems a little odd to reverse search from the description string back to the object. That didn't sit well with me so I'm trying to implement my own search using UISearchController. 

In terms of code, my evaluation has run out so probably not a good use of your time to look at this but I really appreciate the offer.

Kind regards

Karl

0
Sophi
Telerik team
answered on 09 Feb 2016, 08:51 AM
Hi Karl,

The autoComplete:didAutoComplete method returns the string used to complete your input. 
If you want to get the TKAutoCompleteToken object of the chosen item you can override the autocomplete:didAddToken method which provides you with the whole object not just the string.
-(void)autoComplete:(TKAutoCompleteTextView *)autocomplete didAddToken:(TKAutoCompleteToken *)token{
     
}
I hope this helps.

Regards,
Sophi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
AutoCompleteTextView
Asked by
Karl
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Karl
Top achievements
Rank 1
Sophi
Telerik team
Share this question
or