开发者

Connect items to a (specific index in) an array from Interface Builder

This one ought to be a softball for the Objective-C pros out there:

Is there a way to connect an interface builder object to an element of an NSArray in Objective-C? The connecting would normally be done with IBOutlet, as in:

@interface ViewController : UIViewController {
    IBOutlet UILabel *label1;
    IBOutlet UILabel *label2;
    IBOutlet UILabel *label3;
    //...
}

Can I put 开发者_C百科the labels in an NSArray and still attach them to objects in interface builder?


You should be able to use IBOutletCollection, which is essentially an array of IBOutlets. Use this property declaration:

@property (nonatomic, retain) IBOutletCollection(/*whatever object you want an array of e.g. UILabel*/) NSArray *seats;

You will be able to connect multiple objects of one type to this in Interface builder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜