Tutorial :Problem with thread and initialization


I have a problem with my code. I lunch the thread and this thread have a NSTimer. I must remember a variabile location but when i repeat the method i reinitialize these and i lose the progress. Can you help me? Thanks

My code:(these isn't my very code but is the same situation. I want remeber the number of the i but when restart the methods the program reinitialize the i)

-(void)callDectectionMove:(Movement*)tempMovement{          int i = 0;        i++;        if(i == 5)        return;        [NSTimer scheduledTimerWithTimeInterval:timeToCatch target:self selector:@selector(detectMovement) userInfo:nil repeats:NO];      }          -(int)detectPositionMovement:(float)cordX:(float)cordY:(float)cordZ:(float)sensibility{          [NSThread detachNewThreadSelector:@selector(callDectectionMove) toTarget:self withObject:tempMovement];     }  


i is defined as local callDectectionMove and very time you call callDectectionMove new i will be initialized.

on every call you want to make use of same i object then you have make use static int i.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »