iphone - Indexed UILabels Objective-C -
i programming iphone application , need uilabels. example: have 10 labels named label1, label2, label3 etc. , label1.text = @"1", label2.text=@"2" etc. there way in for-loop. for(int = 1, i<11,i++){labeli.text = ...} ? thx helping.
set tag each label , access value follows,
for(int i=1; i<=10;i++) { uilabel *lab=(uilabel *)[self.view viewwithtag:i]; [lab settext:[nsstring stringwithformat:@"%d",i]]; }
or else follows,
nsarray *labels=[nsarray arraywithobjects: label1, label2, nil]; int i=1; for(uilabel *label in labels) { [label settext:[nsstring stringwithformat:@"%d",i]]; i++; }
Comments
Post a Comment