Callback for deleting NSTokenField Tokens

824 views Asked by At

In NSTokenField ,it seems while deleting tokens there is no delegate method exists.

I have tried making Wrapper Delegate:

#import "tokenDelegate.h"

@implementation tokenDelegate
@synthesize token,owner; 

-(id)initWithWrappedToken:(id)token1 owner:(id<TokenWrapperDelegate>)owner1
{
    self.owner = owner1;
    self.token = token1;
    return self;

}

-(void)dealloc {
    [owner tokenWasDeleted:self.token];
    self.token = nil;
    [super dealloc];
}


@end

and for Owner i tried:

- (NSString *)tokenField:(NSTokenField *)tokenField editingStringForRepresentedObject:(id)representedObject;
{ 
    del = [[tokenDelegate alloc] initWithWrappedToken:nil owner:self];
    del.token = representedObject;
    [del release];
    return [representedObject description];

}

-(void)tokenWasDeleted:(id)token
{
    NSLog(@"token %@",token);
}

Problem is:

While editing "tokenWasDeleted" is calling. (that is fine). but when i select a token then directly delete "tokenWasDeleted" is not calling.

Can anyone help what to do with this so that i can get index of the token which is deleted.

Thanks, Neelam Verma

1

There are 1 answers

1
anurodhp On

just add an observer for the tokenfeilds change : [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(actionhere) name:NSControlTextDidChangeNotification object:nil];

this will be called when tokens are added and removed.