Iphone 是否可以创建for循环更改属性';s

Iphone 是否可以创建for循环更改属性';s,iphone,objective-c,xcode,Iphone,Objective C,Xcode,正如所问的问题,我想知道是否有可能通过for循环的int来更改属性的值 例如: 控制器h: @property (weak, nonatomic) IBOutlet UILabel *lblTeamName1; @property (weak, nonatomic) IBOutlet UILabel *lblTeamName2; @property (weak, nonatomic) IBOutlet UILabel *lblTeamName3; 控制器 @synthesize pro

正如所问的问题,我想知道是否有可能通过for循环的int来更改属性的值

例如:

控制器h:

 @property (weak, nonatomic) IBOutlet UILabel *lblTeamName1;
 @property (weak, nonatomic) IBOutlet UILabel *lblTeamName2;
 @property (weak, nonatomic) IBOutlet UILabel *lblTeamName3;
控制器

 @synthesize property lblTeamName1;
 @synthesize property lblTeamName2;
 @synthesize property lblTeamName3;     

 for(int i = 0;i <= 3;i++)
 {
  lblTeamName(i).text = @"something";
 }
@合成属性lblTeamName1;
@合成性能lblTeamName2;
@合成性能lblTeamName3;

对于(inti=0;i,您可以将属性放入
NSMutableArray
中,并在其上循环

NSMutableArray *arr = [[NSMutableArray alloc] init];
[arr addObject:lblTeamName1];
[arr addObject:lblTeamName2];
[arr addObject:lblTeamName3];

for(UILabel *label in arr) {
  label.text = @"something";
}

我不是100%确定,但我认为没有任何东西像Java反射那样可以手动获取定义的属性并更改值。因此,您必须使用额外的数组来获得该行为。

您可以这样做

for (int i=1; i<4; i++) {
    UILabel *label = [self objectForKey:[NSString stringWithFormat:@"lblTeamName%i", i]];
    label.text = @"blah";
}
for(int i=1;i