问题
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 the labels in an NSArray and still attach them to objects in interface builder?
回答1:
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.
来源:https://stackoverflow.com/questions/4402801/connect-items-to-a-specific-index-in-an-array-from-interface-builder