我得到了一个NSTokenField,我通过setObjectValue设置了令牌:[NSArray ..]和自定义对象。我实现了一般NSTokenFieldDelegate方法:NSTokenField选择的令牌
- (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)_tokens atIndex:(NSUInteger)index
- (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject
- (NSTokenStyle)tokenField:(NSTokenField *)tokenField styleForRepresentedObject:(id)representedObject
- (BOOL)tokenField:(NSTokenField *)tokenField hasMenuForRepresentedObject:(id)representedObject
- (NSMenu *)tokenField:(NSTokenField *)tokenField menuForRepresentedObject:(id)representedObject
- (BOOL)tokenField:(NSTokenField *)tokenField writeRepresentedObjects:(NSArray *)objects toPasteboard:(NSPasteboard *)pboard
- (NSArray *)tokenField:(NSTokenField *)tokenField readFromPasteboard:(NSPasteboard *)pboard
一切似乎是工作,因为我看到了令牌在没有编辑的文本字段。
由于这是一个文本框(不可编辑),用户可以选择文本(在这种情况下标记)。当用户点击一个标记时,它被标记为选中。
现在,我试图找出选定令牌(鼠标向下动作后),但似乎我无法从NSTokenField访问它,也不是的NSTextField也没有的NSControl。
我尝试使用tokenField.selectedCell,它给了我NSTokenFieldCell:0x6000001c2b20,一个对象不会改变我的选择。当我询问selectedCell的表示对象时,我得到了一个空引用。
任何人都知道我们如何从NSTokenField访问选定的令牌?
Wonderview,只见它通过NSTextView可能得到的选择,但我错过了NSTokenField的链接来访问NSTextView,fieldEditorForView:是魔术方法在这里。谢谢!我能够记录选定的对象:) –
它被埋葬在文档中。我花了一段时间才找到它。 – SSteve