寻找一种使用NSArray作为一堆按钮的插座的方法 [英] Looking for a way to use an NSArray as an outlet for a bunch of buttons

查看:95
本文介绍了寻找一种使用NSArray作为一堆按钮的插座的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用户界面有四个按钮,他们都将共享一些常见的行为,如跟踪区域创建一样的东西。我要找的是一个解决方案,所以我不必这样做:

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

解决方案像这样:

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

这可能吗?

推荐答案

iOS 4.0添加了 IBOutletCollection 在Interface Builder中连接到多个对象。但是,Mac OS X不支持插座集合。

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.

如果您想要支持将其添加到Mac OS X,请在 http://bugreporter.apple.com

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

这篇关于寻找一种使用NSArray作为一堆按钮的插座的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆