Identifying the selected item when autocomplete

4 posts, 0 answers
  1. Karl
    Karl avatar
    2 posts
    Member since:
    Jul 2015

    Posted 01 Feb Link to this post

    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. 

  2. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 04 Feb Link to this post

    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
  3. DevCraft banner
  4. Karl
    Karl avatar
    2 posts
    Member since:
    Jul 2015

    Posted 04 Feb in reply to Adrian Link to this post

    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

  5. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 09 Feb Link to this post

    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
Back to Top
DevCraft banner