NSTokenField устанавливает максимальное количество токенов
Допустим, у меня есть TokenField, где пользователь может указать, кому должно быть отправлено сообщение. Но я не хочу, чтобы пользователь мог вводить более 3 токенов.
Есть ли способ добиться этого?
1 ответ
Решение
Воплощать в жизнь NSTokenField
делегат 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;
}