可以有一个可变的插座名称吗?例如,您有10个标签(可能是公交车上的座位)。每个都有一个outlet,seat1 seat2等。是否可以有一个for循环,将@"seat“连接到递增整数。这样我就可以访问seat1,seat2 outlet,而不必单独指定它。这不起作用,但让我想要实现的目标变得更清晰了。
int i;
for (i = 0; i < [seatarray count]; i++)
{
[@”seat” stringByAppendingString[ i stringValue]] = @””;
}
发布于 2010-11-25 00:25:22
启动iOS4您可以使用IBOutletCollection
,它允许将多个实例连接到代表对象数组的单个插座,例如只能存储UILabels的IBOutletCollection:
@property (nonatomic, retain) IBOutletCollection(UILabel) NSArray *seats;
发布于 2010-11-25 00:24:08
在加载时自己创建数组可能会更简单:
self.seatarray = [NSArray arrayWithObjects:seat1, seat2, ..., seatN, nil];
发布于 2010-11-25 00:30:56
你应该能够用键值编码来做到这一点,比如(未测试的代码)
for (int i = 0; i != 10; ++i) { [self setValue:@"foo" forKey:[@"seat" stringByAppendingFormat:@"%d", i]]; }
https://stackoverflow.com/questions/4268972
复制相似问题