Is it ok to send normal messages via Interface Builder's binding’s model key path?

穿精又带淫゛_ 提交于 2019-12-13 05:16:40

问题


Is it ok to send normal messages via Interface Builder's binding’s model key path?

I want to enable some menu items only if the main window of my application is visible. I simply tried the following to see what would happen:

In the bindings inspector of the menu item i bind Availability-Enabled to the AppDelegate and set the model key path to self.window.isVisible.

This seems to work well, but is it meant to be used like this? Legal in the AppStore?
A little exclamation mark appears next to my model key path..


回答1:


This binding is legal if the model property (isVisible) conforms to KVO (key-value observing), because bindings are implemented using KVO.

(UPDATED) NSWindow has several documented binding keys, including the key visible. Since the standard KVC search pattern would look for isVisible for the key visible, what you're doing will probably always work. But you would be better off just binding to visible, since that's documented.

The important lesson is that you should only bind to keys that are documented for Cocoa bindings, or keys that are documented to be KVO-compliant.

The exclamation mark is Xcode's way of warning you that it doesn't know if the binding is legal. You can hover your mouse pointer over it for a tooltip:



来源:https://stackoverflow.com/questions/26141296/is-it-ok-to-send-normal-messages-via-interface-builders-binding-s-model-key-pat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!