0

I have a number of programmatically generated UILabels in a UIView (one for each record in the database). I want these to update periodically (say once every 5 seconds) but since they're dynamic it's proving tough to get a "handle" on them to change their values.

Anyone have an idea how to do this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gerard
  • 4,818
  • 5
  • 51
  • 80

2 Answers2

1

Upon creation I would set the tag for each label, incrementing each tag value in parallel with the index of the array that you're creating them from. Then you can grab them in whatever selector you declare for your CADisplayLink object from their particular view using

for (int i = 0; i < [arrayOfData count]; i++){

UILabel *label = (UILabel*)[self.view viewWithTag:i];

//update label

}

Hope I understood your question correctly

Chris Tetreault
  • 1,973
  • 13
  • 19
0

there are many ways, first you need to keep a reference to the labels... an array should bee good, and it's probably better have a custom label with a model, so you actually change the values on the model and you need just to send a message to the label to redraw the content, and you can do that in this way:

[labelArray makeObjectsPerformSelector:@selector(yourMethodToRefreshTheContent)];

you can even pass a object but this mean that will be the same object for all the labels

[labelArray makeObjectsPerformSelector:@selector(valueSetter) withObject:newValue];
Manu
  • 788
  • 5
  • 10