与 ValueTransformer 绑定时 NSColorWell 无法打开
我有一个 NSColorWell
,它绑定到一个包含 NSString
实例的属性,该实例通过我的 ColorTransformer 转换为 NSColor
(>NSValueTransformer
)。它本质上是将 #FF0000
之类的内容转换为 NSColor
。这按预期工作,但单击时 ColorWell 不再打开其窗格。当我禁用绑定时,它会再次起作用。有什么线索可以说明我在这里做错了什么吗?
I have an NSColorWell
, which is bound to a property that contains an NSString
instance, which get's transformed into an NSColor
through my ColorTransformer (NSValueTransformer
). It essentially transforms something like #FF0000
into an NSColor
. This works as expected, but the ColorWell no longer opens it's Pane when clicked. When I disable the binding, it works again. Any clues to what I'm doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
中返回 YES
在
+(BOOL)allowsReverseTransformation
苹果文档示例让它返回 NO,但是默认实现让它返回 YES。理论上,其背后的原因非常简单:苹果不希望您的用户能够设置一种颜色,从而使应用程序崩溃(因为未实现反向转换)。 那么您可能应该实施
如果您还没有这样做, 以确保这种情况不会发生。 (如果你不苹果的文档说它会调用 - (id)transformedValue:(id)value)
return YES in
+(BOOL)allowsReverseTransformation
the apple docs example has it return NO, however the default implementation has it return YES. The reasoning behind this is in theory simple enough: apple doesn't want your users to be able to set a color which will then crash the app (being that a reverse transform was not implemented). You should then probably implement
to make sure this doesn't happen, if you haven't done so already. (If you don't apple's docs say it will call - (id)transformedValue:(id)value)