reset NSTimer

hello,

I would like to change the interval time of the NSTimer after something happened.

the problem is that the interval ks first at 0.05 and should be at 0.045 later. after something else happend it should be 0.04 and so on.

but if I write it like this


if (y == 1) {

moveObjectTimer = nil;

[moveObjectTimerinvalidate];

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval: (0.045) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}


if (y == 2) {

moveObjectTimer = nil;

[moveObjectTimerinvalidate];

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval:

(0.04) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}


if (y == 3) {

moveObjectTimer = nil;

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval: (0.041) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}

or like this


if (y == 1) {

moveObjectTimer = nil;

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval: (0.045) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}


if (y == 2) {

moveObjectTimer = nil;

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval:

(0.04) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}


if (y == 3) {

moveObjectTimer = nil;

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval: (0.041) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}


it is every time the same.

the image moves at an interval like 0.00000001 or something like that.


This is the interesting code can you help me ?


if (y == 1) {

moveObjectTimer = 0;

[moveObjectTimerinvalidate];

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval: (0.045) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}

if (y == 2) {

moveObjectTimer = 0;

[moveObjectTimerinvalidate];

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval: (0.04) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}

[lablesetText: [NSStringstringWithFormat:@"%3.2f", y]];

}


- (void)viewDidLoad

{

[superviewDidLoad];

if (y == 0) {

[moveObjectTimerinvalidate];

moveObjectTimer = [NSTimerscheduledTimerWithTimeInterval: (0.05) target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];

}

}


@end

iMac, OS X Mavericks (10.9.1)

Posted on Feb 24, 2014 10:36 AM

Reply
3 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

reset NSTimer

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.