Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

superbeginer

macrumors newbie
Original poster
Sep 20, 2009
1
0
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
 

firewood

macrumors G3
Jul 29, 2003
8,108
1,345
Silicon Valley
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.