Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a way to use an NSArray as an outlet for a bunch of buttons

My user interface has four buttons and they all will share some common behaviour, like tracking area creation a things like that. What I'm looking for is a solution so I don't have to do this:

@interface MyController : NSWindowController {
    NSButton * button1;
    NSButton * button2;
    NSButton * button3;
    NSButton * button4;
}
@property (nonatomic) IBOutlet NSButton * button1;
@property (nonatomic) IBOutlet NSButton * button2;
// and so on
@end

I would like to have a solution like this one:

@interface MyController : NSWindowController {
    NSMutableArray * buttons;
}
@property (nonatomic) IBOutlet NSMutableArray * buttons; 
// tell interface builder to place all buttons here
@end

Is this possible?

like image 606
Maurício Linhares Avatar asked Jan 27 '11 19:01

Maurício Linhares


1 Answers

iOS 4.0 added IBOutletCollection, which allows an outlet to be connected to multiple objects in Interface Builder. However, Mac OS X does not support outlet collections.

If you'd like to voice support for adding it to Mac OS X, please file an enhancement request at http://bugreporter.apple.com.

like image 185
retainCount Avatar answered Oct 18 '22 23:10

retainCount