问题
Cocoa for Mac OS X support Cocoa Binding technology, reducing need of glue code between your views and your models.
Recreating Cocoa Bindings on top of KVC on KVO seems doable with the help from cocotron source code.
Is there any technical or conceptual reason why Cocoa Bindings are not part of the SDK ? I'm thinking about performance, lack of garbage collection, lack of KVC support from UI elements (UISlider for instance).
回答1:
Bindings on the desktop requires:
- All suitable UI components to expose bindings for their important properties
- Implementation of
NSArrayController
infrastructure for handling selection
On iOS, point 2 becomes less of an issue. It is rare (and perhaps even a bad UI design) to have a master-detail view layout where multiple selection is possible. This is where NSArrayController
really comes into its own.
Bindings for a UITableView become less practical as the current NSArrayController
design doesn't stretch to multiple sections, titles etc.
Point 1 would be useful to have. However it requires a large quantity of work by Apple to implement bindings support in all the UIKit controls. I assume it's never become a high enough priority for them to implement.
来源:https://stackoverflow.com/questions/4706247/is-there-any-technical-conceptual-reason-why-ios-does-not-support-cocoa-bindings