IPhone Timer?

Discussion in 'iOS Programming' started by cthesky, Feb 28, 2012.

  1. cthesky macrumors member

    Aug 21, 2011
    Hi all,

    I need develop an Education Application which allows Student answers some questions within a limited time. For example, in level 1 Student need to answer 10 questions within 2 minutes ... I need to display the time remaining on the view too...

    I am not sure how to do this... Is it using NSTimer? And is it fire an event / method to change the time remaining displayed on the view every second by using scheduledTimerWithTimeInterval?

    Anyway, I would like to hear some ideas and opinions from you all. Hope someone can share their opinions with me. Thanks a lot. :)

    Any ideas and suggestions are welcome. :)
  2. ArtOfWarfare macrumors G3


    Nov 26, 2007
    You're going to want something like this:

    updatingTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTimer) userInfo:nil repeats:NO];
    Also, when the timer first starts, you should store that time somewhere. Then, each time updateTimer is called, it should calculate how much time is left. An NSTimer won't actually fire exactly 1 second after it's set, but rather 1 second + a tiny fraction of a second. These tiny fractions will build up over the course of a few minutes, until the timer is way off. Thus why you calculate how much time is left based on the current time and the time that it started at.

    Sorry if that's a bit confusing.

Share This Page