0

while typing inside NSTokenField I show suggestions for this value, with GetCompletionStrings from NSTokenFieldDelegate

public override string [] GetCompletionStrings (NSTokenField tokenField, string substring, nint tokenIndex, nint selectedIndex)
        {
            //return my values
        }

but if I will completely remove all symboled from NSTokenFiled this event won't be fired.

I need to catch notification when NSTokenFiled string value will changed or cleared or updated, without click enter button.

I use custom nstoken field TokenField : NSTokenField inside it I had override DidEndEditing, like this :

public override void DidEndEditing (NSNotification notification)
        {
            if (EditingFinished != null) {
                EditingFinished (null, null);
            }
            base.DidEndEditing (notification);
        }

this is only called after enter clicked , isn't fired on text change...

I also tried to handle change event of my view in view controller, but it is not called

TagsSearchField.EditingFinished += OnTagFilterSet;
        TagsSearchField.Delegate = new TagFieldDelegate ();
        TagsSearchField.Changed += (o, e) => {
        //debug
        };
Nininea
  • 2,671
  • 6
  • 31
  • 57
  • I have also tried to handle event in constructor: [Export ("initWithCoder:")] public TokenField (NSCoder coder) : base (coder) { this.Changed += (o, e) => { //debug }; } but still no result – Nininea Nov 03 '16 at 07:46

2 Answers2

1

I set Action 'Sent On End Editing ' to Token Field, in xib file and it works now .

After this Change event is called

enter image description here

Nininea
  • 2,671
  • 6
  • 31
  • 57
0

You can use the Changed event to capture all editing changes with the NSTokenField; including clear, clipboard cuts, etc..

tokenField = new NSTokenField(new CGRect(100, 100, 300, 40));
tokenField.Delegate = this;
tokenField.Changed += (object sender, EventArgs e) =>
{
    Console.WriteLine($"changed: {tokenField.StringValue}");
    var tokenArray = tokenField.ObjectValue as NSArray;
    for (nuint i = 0; i < tokenArray.Count; i++)
    {
        Console.WriteLine(tokenArray.GetItem<NSString>(i));
    }
};
View.AddSubview(tokenField);
SushiHangover
  • 73,120
  • 10
  • 106
  • 165