2 daffodilgirl DaffodilGirl 于 2012.11.14 11:36 提问

怎么样能实现改写for循环属性?

hi我又来提问了。
我的问题是我想知道怎么样能实现for循环中int的属性修改?

例子:

controller.h:

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

controller.m

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

 for(int i = 0;i <= 3;i++)
 {
  lblTeamName(i).text = @"something";
 }

不知道这样能不能实现哦?

2个回答

MrsSeven7
MrsSeven7   2012.11.14 14:25
已采纳
for (int i=1; i<4; i++) {
    UILabel *label = [self objectForKey:[NSString stringWithFormat:@"lblTeamName%i", i]];
    label.text = @"blah";
}
DaffodilGirl
DaffodilGirl 谢谢
接近 5 年之前 回复
g989_1314125
g989_1314125   2012.11.14 13:04

用NSMutableArray啊

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

for(UILabel *label in arr) {
  label.text = @"something";
}
Csdn user default icon
上传中...
上传图片
插入图片