Link to home
Start Free TrialLog in
Avatar of Kekosavar
Kekosavar

asked on

nstime in for statement

i want to call a method in per 5 seconds. also there is a count and after 20 seconds if the count is equal to 4 then do something..like below code..

but I see, it writes NSLog(@"denemelik"); at every 5 second not after if cnt is 5. I think it must write the "denemelik" after 25 seconds because of if (cnt == 5 )

I hope you understand what I mean..Can you help me? How can I solve this problem?
for (int i=1; i<6; i++) {
    [NSTimer scheduledTimerWithTimeInterval: 5.0
                                     target: self
                                   selector:@selector(onTick:)
                                   userInfo: nil repeats:YES];
    cnt=i;

}


-(void)onTick:(NSTimer *)timer {
    if(timer)
{
    CLLocation *d =[[CLLocation alloc] init];
    ws6=[[GetData5 alloc]init];
    [ws6 GetWebservice5:@"123abc":d.coordinate.latitude:d.coordinate.longitude:0 :0:@"mesafe" ];
    NSMutableArray *arr = [[NSMutableArray alloc] init];        
    if (cnt == 5 ) 
        NSLog(@"denemelik");
    }
}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jacekmalinowski
jacekmalinowski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial