如何防止从NSTokenField中的数组重复选择。我已经实现了委托完成。
最佳答案
我可以使用这种方法删除所有重复项,这虽然有点笨拙,但确实可行:
// Be sure to set the delegate of your NSTokenfield either in IB or in code.
#pragma mark - NSTokenFieldDelegate
-(NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index{
double delayInSeconds = .1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSArray *aray = [tokenField objectValue];
NSOrderedSet *set = [NSOrderedSet orderedSetWithArray:aray];
aray = [set array];
[tokenField setObjectValue:aray];
});
return tokens;
}
关于objective-c - 处理NSTokenField中的重复选择,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18929784/