如何为 NSApp.dockTile 创建绑定
在 IB 中,很容易将标签或文本字段绑定到某些控制器的 keyPath。
NSDockTile(可通过 [[NSApp dockTile] setBadgeLabel:@"123"] 获得)不会出现在 IB 中,并且我无法弄清楚如何以编程方式绑定其“badgeLabel”属性,就像绑定标签/文本字段/表列一样。
有任何想法吗?
In IB it is easy to bind a label or text field to some controller's keyPath.
The NSDockTile (available via [[NSApp dockTile] setBadgeLabel:@"123"]) doesn't appear in IB, and I cannot figure out how to programmatically bind its "badgeLabel" property like you might bind a label/textfield/table column.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSDockTile 没有任何绑定,因此您的控制器必须手动更新停靠图块。 您可以使用 KVO 来完成此操作,这与绑定它具有相同的效果。
创建一个全局上下文:
然后,在 init 方法中:
然后,您必须实现此方法才能收到关键路径更改的通知:
确保在控制器对象消失时删除观察者。
NSDockTile doesn't have any bindings, so your controller will have to update the dock tile manually. You could do this using KVO which would have the same effect as binding it.
Create a context as a global:
Then, in your init method:
You then have to implement this method to be notified of changes to the key path:
Make sure you remove the observer when the controller object goes away.
如果 NSDockTile 确实支持绑定,则可以使用方法
bind:toObject:withKeyPath:options:
在 badLabel 属性上设置绑定。 检查文档以获取有关使用哪些参数的详细信息。 如果它不起作用,您可以在控制器类中实现键值观察并在每次值更改时更新标签,甚至重写 NSDockTile 以创建绑定兼容的子类。If NSDockTile does support bindings, you can use the method
bind:toObject:withKeyPath:options:
to set up bindings on the badgeLabel property. Check the documentation for details on which arguments to use. If it doesn't work, you could either implement key value observing in your controller class and update the label each time the value changes, or even override NSDockTile to create a bindings compatible subclass.我在 NSDockTile、控制器、数据源上尝试了
bind:toObject:withKeyPath:options:
的许多变体。 我无法找出有效的组合。 或者,是否有一种方法可以将 BatchController 对象绑定到数据源,然后更新徽章? 如何获取 NSObject 并使其可绑定?I've tried lots of variations of
bind:toObject:withKeyPath:options:
on NSDockTile, on a controller, on the data source. I can't figure out a combination that works. Alternately, is there a way of having a BatchController object that can be bound to the data source, and it then updates the badge? How do I take an NSObject and make it bindable?