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

Remove Token from AutocompleteTextView Programmatically

2 Answers 73 Views
AutoCompleteTextView - Xamarin.iOS
This is a migrated thread and some comments may be shown as answers.
Mayank
Top achievements
Rank 1
Mayank asked on 20 Dec 2018, 02:47 PM
Hello Team,

I am getting Issue while Remove Token Programmatically.

Steps i Follow:

1) I am Adding my Token Programmatically, which is successfully Add in the AutoCompleteTextView,
I am adding Token using Below Method.
=> this.Autocomplete.AddToken(new TKAutoCompleteToken(new NSString("DummyToken")));

2) Now when i try to remove the same Token Programmatically, I ma using Below Code,
=> this.Autocomplete.RemoveToken(new TKAutoCompleteToken(new NSString(DummyToken)));

But it is not removing from AutoCompleteTextView.

I spent many hours but not getting success,

So, if anyone can help me on this, it will be appreciated.

Thanks,

2 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 20 Dec 2018, 05:31 PM
Hi Mayank,

I would investigate to make sure that token reference is even valid, it doesn't look like it would work to me.  You should instead use the NSArray that holds the tokens to get an actual reference to the token you want to remove.

For example, here's how to get a reference to the last token in the array:

var tokens = _autocomplete.Tokens();
var lastTokenIndex = tokens.Count - 1;
var lastToken = tokens.GetItem<TKAutoCompleteToken>(lastTokenIndex);

Now, with a valid reference to the token in the Tokens array, you can use it for RemoveToken() method:

_autocomplete.RemoveToken(lastToken);

I've attached a demo, to see it working:

1 - Select 2 items in the AutoCompleteView
2 - Click the button to remove the last token

If you would like more guidance on finding specific items in an NSArray, here's a good example in StackOverflow.

Regards,
Lance | Tech Support Engineer, Sr.
Progress 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
Mayank
Top achievements
Rank 1
answered on 03 Jan 2019, 10:35 AM
Thanks, its working with your solution.
Tags
AutoCompleteTextView - Xamarin.iOS
Asked by
Mayank
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Mayank
Top achievements
Rank 1
Share this question
or