假设我有一个 TokenField,用户可以在其中输入消息应发送给谁。 但我不希望用户输入超过3个Token。
有办法实现吗?
最佳答案
实现 NSTokenField
委托(delegate) tokenField:shouldAddObjects:atIndex:
// return an array of represented objects you want to add.
// If you want to reject the add, return an empty array.
- (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)tokens atIndex:(NSUInteger)index
{
if (index>2) {
return [NSArray array];
}
NSLog(@"%@-- %d %d", tokens, [tokens count],index);
return tokens;
}
关于cocoa - NSTokenField 设置最大 Token 数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18272390/