如何在循环内延迟执行?也许NSTimer?

Bha*_*kar 1 iphone ipad

我正在使用for循环,因为我正在使用else if条件.在其中一个else if我想继续for循环一些延迟.是否可以使用continue语句NSTimer?如果可能,我该如何使用continue语句NSTimer.

for(int i = 0; i<[array count];i++){

    else if (condition)
    {
    }
    else if (condition)
    {
    }
    else if (condition)
    {
    }
    else if (condition)
    {
       // Here I want to continue the for loop with some delay
    }
    else if (conditions)
    {
    }
    else
    {
    }

}
Run Code Online (Sandbox Code Playgroud)

请任何人帮助我

Ann*_*nne 5

使用NSThread sleepUntilDate:NSDate dateWithTimeIntervalSinceNow:延迟.

例:

for(int i=0; i<5; i++){

    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
    NSLog(@"Delaying");

}
Run Code Online (Sandbox Code Playgroud)

输出:

15:57:46.383 Delaying
15:57:47.386 Delaying
15:57:48.388 Delaying
15:57:49.389 Delaying
15:57:50.391 Delaying
Run Code Online (Sandbox Code Playgroud)