> On 8 Apr 2016, at 10:32 PM, Graham Cox <graham....@bigpond.com> wrote:
> 
> Your controller might, and could effect the binding in code, using -[NSObject 
> bind:toObject:withKeyPath:options:] and an outlet to the group view. As work 
> goes, that’s pretty minimal, and affects only the controller, as it should.


I confess I’m unfamiliar with bindings, but I just tried an experiment. In the 
test code, I added the following code to the class acting as a controller:

- (void)        awakeFromNib
{
        [mLabel bind:@"objectValue" toObject:mRadioGroup 
withKeyPath:@"selectedIndex" options:nil];
        
}


Here, mLabel and mRadioGroup are outlets to a text field and the radio group 
created earlier respectively. Because the -bind… method is declared on 
NSObject, it is universal - the controller doesn’t need to import the 
GCRadioGroupView header so it’s completely unaware of its implementation, other 
than that it has a ’selectedIndex’ property. mLabel here represents the 
“model”, though in fact it’s another view. If you want to bind in both 
directions, you have to write two lines of code like this.

This works, the label displays the value of the selected index as expected when 
the radio buttons are operated. Apart from this one line of code in the 
controller, it’s all done in IB (hooking up two outlets and adding the radio 
buttons to the group view). I’d call that about as good as you’re going to get 
unless IB can be made to display the exposed bindings, which unfortunately 
seems to be unsupported (why!!??).

If it bothers you that ‘selectedIndex’ is unique to this class, call it 
whatever you want. It could be ‘selectedTag’ for all it matters, but since you 
need to bind in code, it may as well be descriptive.


—Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to