Question

Im just new in this of programming APPs and I have just started into the world of iOS.

I am trying to learn by myself, just following a course I have found on the net (CS193P - Stanford).

The question is simple, I think.

I would like to implement a chronometer (for a friend who is always late, want to chrono the time I spent waiting him haha), but I don't know how to operate. A "refreshing label"?

Any tips? Thanks in advance.

By the way, I would really appreciate any course you should think is interesting for me.

Was it helpful?

Solution

For this kind of "refreshing stuff", you should use a NSTimer:

//initialize this in your viewDidload
[NSTimer scheduledTimerWithTimeInterval:1.0
    target:self
    selector:@selector(refreshLabel)
    userInfo:nil
    repeats:Yes];

Then, in implement in your controller the method passed in the selector parameter above:

-(void)refreshLabel
{
   //logic here: incrementing some counter and setting in your label
}

If you want a smaller piece of time, just change it in scheduledTimerWithTimeInterval parameter.

This, of course, is just how you would set your label (assuming you have an IBOutlet to one) to be refreshed every second. You still would have to create chrono's logic (incrementing some instance variable, creating some logic to split minutes / seconds, or using NSDate methods). If you still want help with other things, please let us know.

Josh Caswell's links in comments will be a lot helpful to you.

If you with more information about the NSTimer, please read the Apple's documentation: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Timers/Articles/usingTimers.html#//apple_ref/doc/uid/20000807-CJBJCBDE

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top