I’m new to iOS development, just had a quick question. I’m creating an app with 100 UILabel’s. Each label is numbered 0 to 99. The problem is that I dont want to do this for all 100 labels.
output1.text = [[NSString alloc] initWithFormat:@"1"];
output2.text = [[NSString alloc] initWithFormat:@"2"];
.....
output100.text = [[NSString alloc] initWithFormat:@"100"];
Instead I’d like to do this a little more dynamically. Below I’m trying to use loops to dynamically create a string. For example by appending “1.text” to the end of “output” I get the string “output1.text”.
for (int i=0; i< 100; i++) {
outputNameString = [NSMutableString stringWithCapacity:0];
[outputNameString setString:@"output"];
[outputNameString appendString:[NSString stringWithFormat:@"%i.text",i + 1]];
outputNameString = [[NSString alloc] initWithFormat:@"%@",i];
}
“output1” to “output100” are properly declared in the interface section and synthesized properly. Is there something I’m missing here, or is this simply not possible? Any help would be appreciated.
when you create the label.. set them tags from lets say (100—200 )
so .
initialize your label like this..
then get your label like this..and set its text
this should work great..
What is the problem.?