2012-05-24 24 views
0

我不知道如何写这一行。我想要做的是编写一个只能完成一次的语句,并且在完成时标记它自己不再被执行(以避免一个不变的循环),例如白天和黑夜的时间。标记并检查过程是否完成

我觉得要写入的需求:

if ([nightTime timeIntervalSinceNow] <= 0 && "check if already reset or not"){ 
     // The following process has to be done, but only once 

     // reset dayTime (for tomorrow) 

     // stop the current NSTimer 

     // recreate a new NSTimer for nightTime   

    } 

任何人都可以指出我的,我应该用什么正确的方向?

非常感谢!

+0

嗨,
       您需要回拨方法。我猜。如果您不知道您的预期状态(待检查的条件)何时未知或无法由您决定。如果你知道什么时候会遇到这种情况,那么最好有一面旗帜,并将其标记为“是”或“否”。希望这可以给你一个概述。让我知道是否需要进一步。 – iDroid

回答

0

拿一个标志iIsProcessDone

if ([nightTime timeIntervalSinceNow] <= 0 && !iIsProcessDone){ 

     iIsProcessDone = YES; 

     // The following process has to be done, but only once 

     // reset dayTime (for tomorrow) 

     // stop the current NSTimer 

     // recreate a new NSTimer for nightTime   

    } 

而当你想再次调用此过程重置。