How to bind several NSTextFields to entries of an NSMutableDictionary in xib?
It is amazing that the most basic thing to do with binding, goes unanswered in Apple Docs, in Apple sample code, in the dozen or so Cocoa-focused sites and in stackOverflow.
My .xib's FileOwner controller has a NSMutableDictionary property, initialised from a .plist file. Example contents:
{
server = {
host = myServer;
port = 443;
organization = myOrganization;
};
state = "ACTIVE";
mode = 4;
}
I need to bind host , port and organisation to 3 NSTextField instances embedded in a simple view in the .xib, so that the user can edit their values. (port also has a number formatter).
I can't bind directly to the NSMutableDictionary - it's not KVO/KVC compliant on its keys and values.
I tried to use an NSDictionaryController as mediator (bound its contents to my mutable dictionary, but I can't figure out what "controller key" to use. arrangedObjects fails me - there's no array in my contents. "selection" fails me too - there is no selection!
I tried with NSObjectController instead - same thing. No selection, and I can't use "contents" as my controller key.
I want to bind my "host" field to (something).server.host "organisation" to (something).server.organization and "port" to (something).server.port.intValue
Please help. what is something? I'm feeling stupid - this is the most basic binding task I can imagine.
I've done much more complex bindings, but the most simple I can't...
链接地址: http://www.djcxy.com/p/85258.html