Reputation: 745
Hey I am new to mac development and I want to use bindings (xcode 5.1.1).
I want to set the Title of a radio button dynamically by an entry of an array controller. I am looking for something like a syntax description how I can perform it.
e.g. something like value1 WHERE value2="bla"
If I trying to search at google I always find solutions which did it programmatically.
Is there anywhere some examples which show me the syntax I can use in this field?
The picture below should you show what I mean.
Upvotes: 0
Views: 1061
Reputation: 90641
Answering the question as clarified in the comments…
First, bindings is not always the right technology. It can simplify some things, but it can't do everything and even for some of the things that it can do, it doesn't necessarily make them simpler.
Radio buttons are often organized in an NSMatrix
. In that case, you can bind the matrix bindings to track the selection. There are three content-related bindings for a matrix, which can be kind of confusing. The "content" binding is the base. In some cases, it's sufficient. However, if there's a distinction between the object being bound and the value that should be shown by the cells of the matrix, then you can bind the "contentValues" binding to be a subpath of the content binding. That is, it needs to be the same as the content binding with possibly additional elements added to the end of the model key path.
Furthermore, if you want the selected object to be distinct from the content object, you can bind "contentObjects" to a subpath of the content binding.
For example, there may be an array controller whose content is a bunch of Person
objects. The matrix content
binding might be bound to that array controller's arrangedObjects
. If you leave it like that, the cells of the matrix will be populated from the description
of each Person
object. However, you could bind the matrix's contentValues
to the array controller, arrangedObjects
, model key path fullName
. Then, the matrix cells will be populated with the full name of each Person
object.
If you then bind the matrix's selectedObject
binding to a property on your window controller, that property will be set to the selected Person
object each time the matrix selection changes. If you would prefer, you could bind the matrix's contentObjects
binding to the array controller, arrangedObjects
, model key path uniqueID
. In that case, the window controller property would not be set to the selected Person
object itself, but to its uniqueID
property.
Alternatively, you could bind the matrix's selectedIndex
binding to a controller property. If you use the window controller, then that just directly sets a property on the window controller to indicate the index of the matrix's selection. Or you could bind it to the array controller's selectedIndex
property, in which case the selection is "stored" in the array controller.
Upvotes: 1
Reputation: 5665
You need a keypath that takes no parameter as described in the key-value coding (KVC) reference.
By binding to an array controller's selection, if the selection collection is one object with a property or method "value1," then the binding runtime is calling the method valueForKeyPath:@"value1"
.
The NSObject protocol has performSelector:withObject
, but there is nothing like valueForKeyPath:withObject
in the KVC protocol or the NSKeyValueBindingCreation protocol
That said, registering dependent keypaths can provide some equivalent behavior...
+ (NSSet*) keyPathsForValuesAffectingValue1
{
return [NSSet setWithObjects:@"value2",nil];
}
... and that would ensure that any time value2 changes, the binding to value1 is re-evaluated.
Upvotes: 0