Reputation: 532
I hope you can help me as I cannot retrieve the text from an NSTokenField using the following logic. The issue I am experiencing with this code is that it will return to me the full string of all the tokens. I want to be able to only retrieve the text that has been selected by the user. Can this be done ?
- (IBAction)onRemoveSelectedCategory:(id)sender
{
NSLog(@"CategoryTokenField Selection: %@", [_categoryTokenField.selectedCell stringValue]);
}
Any help is greatly appreciated.
Thanks, Michael
Upvotes: 0
Views: 345
Reputation: 17382
You need to use the representedObject
method of the selectedCell
- (IBAction)onRemoveSelectedCategory:(id)sender
{
NSLog(@"CategoryTokenField Selection: %@", [_categoryTokenField.selectedCell representedObject]);
}
or
-(void) onRemoveSelectedCategory:(id)sender
{
if([sender respondsToSelector:@selector(representedObject)]){
NSCell *cell = (NSCell *)sender;
NSString *token = cell.representedObject;
}
}
Upvotes: 1