变量IBOutlet名称? [英] Variable IBOutlet name?
问题描述
是否可以使用可变的插座名称?
例如,您有10个标签(也许在公共汽车上有座位)。每个都有出口,seat1 seat2等。
是否可能有一个for循环
,它将@ seat连接到增量整数。这样我就可以访问seat1,seat2出口,而不必单独指定它。
这行不通,但使我想达到的目标更加清晰。
Is it possible to have a variable outlet name?. For example you have 10 labels (perhaps seats on bus). each has an outlet, seat1 seat2 etc. Is it possible to have a for loop that concatenates @"seat" to the increment integer. So that I can access seat1, seat2 outlet without having to specify it individually. This doesn’t work but makes it a bit clearer what I am trying to achieve.
int i;
for (i = 0; i < [seatarray count]; i++)
{
[@"seat" stringByAppendingString[ i stringValue]] = @"";
}
推荐答案
从iOS4开始,您可以使用 IBOutletCollection
允许将多个实例连接到代表一个对象数组的单个出口,例如IBOutletCollection仅可存储UILabel:
Starting iOS4 you can use IBOutletCollection
which allows to connect multiple instances to a single outlet which represents an array of objects, e.g. IBOutletCollection which can store UILabels only:
@property (nonatomic, retain) IBOutletCollection(UILabel) NSArray *seats;
这篇关于变量IBOutlet名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!