问题描述
这个应该是Objective-C专业人员的垒球:
This one ought to be a softball for the Objective-C pros out there:
有没有办法将界面构建器对象连接到NSArray的元素在Objective-C?连接通常用 IBOutlet
完成,如:
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;
//...
}
我可以将标签放入NSArray并仍将它们附加到界面构建器中的对象?
Can I put the labels in an NSArray and still attach them to objects in interface builder?
推荐答案
您应该能够使用IBOutletCollection,它本质上是一个数组IBOutlets。
使用此属性声明:
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.
这篇关于将项目连接到Interface Builder中的(特定索引)数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!