cocoa - NSTokenField set maximal number of Token -
let's say, have tokenfield, user can input message should sent to. don't want user can input more 3 token.
is there way achieve this?
implement nstokenfield delegate tokenfield:shouldaddobjects:atindex:
// return array of represented objects want add. // if want reject add, return 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; }
Comments
Post a Comment