我正在使用for
循环,因为我正在使用else if
条件。在其中一个else if
中,我希望延迟for
循环。是否可以在NSTimer
中使用continue语句?如果可能,我如何在NSTimer
中使用continue语句。
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
{
}
}
请任何人帮助我
答案 0 :(得分:5)
使用NSThread sleepUntilDate:
和NSDate dateWithTimeIntervalSinceNow:
延迟。
示例:
for(int i=0; i<5; i++){
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
NSLog(@"Delaying");
}
输出:
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
答案 1 :(得分:0)
对我来说,你想要暂停线程,而不是使用NSTimer。所以if语句中的内容如下:
[NSThread sleepforTimeInterval:]; 继续;
答案 2 :(得分:0)
您可以简单地使用sleep(&lt; #sleep duration#&gt;);