0

这就是问题所在,我想在 xCode 中绘制一个动态屏幕,具体取决于来自 webServer 的标签数量,是这样的......

for (int i = 0; i< [webserver.arraylabels count]; i++){
   UILabel *label[i];
   label[i] = [functions createLabel:[[webserver.arraylabels objectAtIndex:i] textLabel]
                                                   locationX:[webserver.arraylabels objectAtIndex:i] locationX]
                                                   locationY:[webserver.arraylabels objectAtIndex:i] locationY]
                                                 heightControl:[webserver.arraylabels objectAtIndex:i] heightControl]
                                                  widthControl:[webserver.arraylabels objectAtIndex:i] widthControl]
                                                adjustmentControl:UIViewAutoresizingFlexibleRightMargin];

[cell addSubview:label[i]];
}

[functions createLabel...] 是一个返回 UILabel 对象类型的函数...

如果我运行它,由于标签名称上的 [i] 会出现错误,我该怎么做?

预先感谢您的支持

4

1 回答 1

0

这就是 H2CO3 的答案

NSMutableArray *arregloControles = [[NSMutableArray alloc]init];

for (int i = 0; i< [webserver.arraylabels count]; i++){
   UILabel *control;
   control = [functions createLabel:[[webserver.arraylabels objectAtIndex:i] textLabel]
                                                   locationX:[webserver.arraylabels objectAtIndex:i] locationX]
                                                   locationY:[webserver.arraylabels objectAtIndex:i] locationY]
                                                 heightControl:[webserver.arraylabels objectAtIndex:i] heightControl]
                                                  widthControl:[webserver.arraylabels objectAtIndex:i] widthControl]
                                                adjustmentControl:UIViewAutoresizingFlexibleRightMargin];

[cell addSubview:control];

[arregloControles addObject:control];
}

并将其召回 H2CO3 建议:

UILabel *label = [arregloControles objectAtIndex:0]; //no casting required

或者

UILabel *label = (UILabel*)[self.view viewWithTag: labelTag];
于 2013-08-14T00:22:25.443 回答