On Thu, 7 Apr 2016 15:36:51 -0400, Nivek Research said: >I have a number of NSMatrix instances that group radio buttons. Most >bind the selectedIndex or selectedTag bindings available on NSMatrix to >a numeric value in a model object. The others bind the contentObjects >and selectedObject binding available on NSMatrix. As NSMatrix is >informally deprecated in OS X 10.8 and later does anyone know a way to >bind multiple NSRadioButtons to a single numeric value as was once done >with selectedIndex or selectedTag such that the selected radio button >follows the numeric value? Similarly does anyone have a way to bind >multiple buttons to a single object value like NSMatrix’s selectedObject >was used previously? Ideally any solution should be backwards compatible >to OS X 10.6 as I still need to support that release. I have searched >the internet though I have not seen a solution that will work without >major changes to my model code. Not that I am not willing to make the >changes. I just wonder if anyone has been enlightened with a cooler solution.
Kevin, Yeah, I keep meaning to file a radar about this. I didn't find any nice way to do this, so I'm mostly still using NSMatrix for radio buttons. Recently, I wrote a little helper class, attached here, that makes it a little easier to use bindings with non-NSMatrix radio buttons. It's not as nice as NSMatrix's built-in IB support, but maybe you'll find it helpful. Cheers, -- ____________________________________________________________ Sean McBride, B. Eng s...@rogue-research.com Rogue Research www.rogue-research.com Mac Software Developer Montréal, Québec, Canada
// // RRRadioBinder.h // // Created on 2016-01-08. // Copyright Rogue Research 2016. All rights reserved. // // This file is encoded as UTF-8. // // $Id: RRRadioBinder.h 31325 2016-01-13 21:23:49Z sean $ /*! \class RRRadioBinder \brief Instances of this class can be used to bind together an integer and a group of radio buttons using Cocoa bindings. It's a replacement for the deprecated NSMatrix and its 'selectedTag' binding. Should be instantiated in a nib file, with an outlet connecting it to controller to bind to and a 'user defined runtime attribute' named 'bindingKeyPath' set to a keypath of the controller. Observation is started in awakeFromNib and stopped in dealloc. */ #import <AppKit/AppKit.h> NS_ASSUME_NONNULL_BEGIN @interface RRRadioBinder : NSObject /// The controller to bind to. @property (readwrite, weak, nonatomic) IBOutlet NSController* bindingController; /// The keypath of the controller to observe. @property (readwrite, copy, nonatomic) NSString* bindingKeyPath; /// The radio buttons to manage. At least 2 should be connected for non-trivial usage. They should all have the same action methed, namely handleRadioButton:. They should all have different tags. @property (readwrite, weak, nonatomic, nullable) IBOutlet NSButton* radioButton0; @property (readwrite, weak, nonatomic, nullable) IBOutlet NSButton* radioButton1; @property (readwrite, weak, nonatomic, nullable) IBOutlet NSButton* radioButton2; @property (readwrite, weak, nonatomic, nullable) IBOutlet NSButton* radioButton3; @property (readwrite, weak, nonatomic, nullable) IBOutlet NSButton* radioButton4; /// The action method that all radio buttons should be connected to. - (IBAction)handleRadioButton:(id)inSender; @end NS_ASSUME_NONNULL_END
RRRadioBinder.m
Description: Binary data
_______________________________________________ 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