用于删除NSTokenFieldCell的回调 [英] Callback for deleting NSTokenFieldCell

查看:115
本文介绍了用于删除NSTokenFieldCell的回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSTokenField和NSTokenFieldCell表示被管理对象。当我通过键入创建一个新的NSTokenFieldCell,我的NSTokenField的委托(一个NSArrayController)用这个方法回调:

I have a NSTokenField with NSTokenFieldCell's that represent managed objects. When I create a new NSTokenFieldCell by typing, my NSTokenField's delegate (an NSArrayController) is called back with this method:

tokenField:representedObjectForEditingString

在此方法中,我为新令牌单元创建一个受管对象,

In this method, I create a managed object for the new token cell and it works as expected.

但是,我找不到一个回调方法删除NSTokenFieldCell,我可以删除我的托管对象。任何人知道这是否存在?如果没有,我想我会以某种方式监控NSTokenField的删除,听起来不太理想。

However, I can't find a callback method for deleting a NSTokenFieldCell where I can remove my managed object. Anyone know if this exists? If not, I guess I would have to somehow monitor the NSTokenField for deletions which sounds less than ideal.

推荐答案

很难理解你要求什么。你真的意味着你正在创建和删除NSTokenFieldCells?我不认为你做 - 一个NSTokenField控件有一个NSTokenFieldCell实例。整个程序集只是将某些字符串(通过NSTokenFieldDelegate协议控制)表示为图形令牌。

It's hard to understand what you're asking for exactly. Do you really mean you're creating and deleting NSTokenFieldCells? I don't think you do - an NSTokenField control has an NSTokenFieldCell instance. The whole assembly just represents certain strings (that you control via the NSTokenFieldDelegate protocol) as graphical "tokens". The cell isn't recreated each time, only what it represents/draws.

您的意思是说,您希望在标记化的字符串

Do you mean to say you want to be notified when a tokenized string is deleted from the field? If so, I'm afraid that's not how it's designed to work. You decide what strings (separated by the tokenizing character set that you told the token field to use) are tokenized and what replacement string (usually a shortened or cleaned-up version) is displayed as the token itself. Therefore, it's up to you to determine whether a "token" that's in your model is now missing and clean it up yourself.

:在Cocoa Bindings中没有这样做的设施。可能最好维护一个-tokensNeedCleaning标志,并以与-setNeedsDisplay:和-displayIfNeeded方法使用NSView相同的方式对待它。这样,当令牌字段被编辑时,您可以调用[self setTokensNeedCleaning:YES]。该方法反过来可以通过-performSelector:withObject:afterDelay:(具有零秒延迟)调用[self cleanTokensIfNeeded],如果needsCleaning标志为YES,则调度清理缺失的令牌。然后它将取消设置标志。

Put simply: there are no facilities for doing this in Cocoa Bindings. It might be best to maintain a "-tokensNeedCleaning" flag and treat it the same way the -setNeedsDisplay: and -displayIfNeeded methods work with NSView. That way, when the token field is edited, you can call [self setTokensNeedCleaning:YES]. That method, in turn, can call "[self cleanTokensIfNeeded]" via -performSelector:withObject:afterDelay: (with a zero second delay), to schedule cleaning up the missing tokens if the needsCleaning flag is YES. It'll then unset the flag.

这个简单的机制保持清除例程不会与每次连续编辑一起运行,而是标记它并调度它在不久的将来运行if它仍然需要。这样,连续调度的-cleanTokensIfNeeded将不会盲目地尝试清理 - 清理调用将合并。

This simple mechanism keeps the cleanup routine from running with each successive edit but rather flags it and schedules it to run in the immediate future if it's still needed. That way, successive scheduled calls to -cleanTokensIfNeeded won't keep blindly trying to clean up - the cleanup calls will be coalesced.

这篇关于用于删除NSTokenFieldCell的回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆