-1

I am trying to track this loop like the time Sec min and Hr. But the display (label) print out this 59,59,59 instead of starting from 0 and going on. So I would like to see the numbers are incrementing live. How do I do that?

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    int i;

    for(i=0; i<60; i++)
    {
        for (int j=0; j<60;j++){
            for(int d=0;d<60;d++){

                self.timer.text =[NSString stringWithFormat: @"%i, %i, %i", i,j,d];
            }
        }
    }


    // Do any additional setup after loading the view, typically from a 
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

0

You have a few problems here:

  • you're blocking the main thread so the app only gets to display the end result of your loop, not the progress. Solution here would be to use CADisplayLink or NSTimer to update the counter once a tick and leave the app free to actually draw the change.

  • you're just doing a loop without any slowdowns and a variable update takes far less than a clock second. This is related to the proposed solution before, but if you want the label to change every second you can set a timer, set it to less then a second (because the time value in the timer is the shortest time to wait) and update the text label by subtracting start time from current time. This is a way that protects you from clock desyncs when your device gets a bigger cpu load.

Alistra
  • 5,177
  • 2
  • 30
  • 42
-1

Your just looping from 0 to 59. You need a 1 second delay to actually increment every second

Zander Brown
  • 637
  • 8
  • 16