Xcode calls int override value for int when called in another function

I am having problems with int increments from one function by calling it in another function.

At the moment, the bit I'm working on is as follows:

in the .h file, I declare int and timer as follows:

int count;
NSTimer *sequenceOn;

in the .m file, my function segment looks like this:

-(void) sequence {
count = 1;

while (count < (target)) {


    sequenceOn = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(imagePlayer) userInfo:nil repeats:NO];

 }
}

-(void)imagePlayer {

 --CODE HERE FOR PLAYING ANIMATION--
    count = count + 1;
}

All of my other code is working fine, and it should play a series of images using the count value to decide which one to play. At the moment, although it only plays the first animation, it will not increase until the next.

Any help would be greatly appreciated.

Thank.

+3
source share
3 answers

, . , , :

-(void)stopTimer {
    [sequenceOn invalidate]; 
    sequenceOn = nil;
}

-(void)sequence {
    [self stopTimer];
    count = 1;
    // start a repeating timer:
    sequenceOn = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self       
                  selector:@selector(imagePlayer) userInfo:nil repeats:YES];
}

-(void)imagePlayer {  
    //--CODE HERE FOR PLAYING ANIMATION--
    count = count + 1;
    if (count >= target) {
        [self stopTimer];
    } 
}
0

scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: NO, , , . , , , imagePlayer .

0

while, count target, , target.

0

All Articles