timer value

Discussion in 'iOS Programming' started by superbeginer, Sep 20, 2009.

  1. superbeginer macrumors newbie

    Joined:
    Sep 20, 2009
    #1
    hi i beginer in obj c
    how get value in timer, my code :

    - (void)viewDidLoad {
    timeval =[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:mad:selector(mypos) userInfo:nil repeats:YES];

    [super viewDidLoad];
    }

    int timecount = 5;
    -(void)mypos{
    int posx;
    posx = (arc4random() % 200)+10;

    if(timecount ==5){
    NSLog(@"My posx %d", posx);

    }

    if(timecount == 0){
    NSLog(@"My posx %d", posx);
    [timeval invalidate];
    }
    timecount = timecount -1;
    }

    debug :
    (timecount == 5) My posx 183
    (timecount == 0) My posx 96

    how to get value to other class, thanks
     
  2. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    Counting ticks doesn't always work properly.

    Try:

    [ NSDate timeIntervalSinceReferenceDate ]

    or

    mach_absolute_time()

    or

    gettimeofday()

    and save a reference time from when you start your NSTimer.
     

Share This Page