2013-02-10 30 views
-6

我想如果按下一個按鈕計時器至極開始。 定時器運行時,它不可能再次按下按鈕。和警報將顯示.. 有你的想法如何實現的呢? 坦克你!backcounting定時器

+1

你需要做一些自己的研究的第一個。 Stackoverflow不是讓人們爲自己工作的地方。你也應該嘗試,以確保您的文章具有正確的語法(如正確的首都,拼寫和文章)。 – 2013-02-10 23:11:43

+0

抱歉,我來自德國,這是我的第一篇文章。我是新來的,下一次我會變得更好! – 2013-02-10 23:15:37

回答

1

創建NSTimer在第一時間按下按鈕,並在定時器是有效的,不允許的動作發生,並彈出您的警報。

Store中的NSTimer在對象上的屬性。

接口:

@property (strong, nonatomic) NSTimer *timer; 

實現:

- (IBAction)buttonClicked:(id)sender 
{ 
    if(self.timer == nil || ![self.timer isValid]) { 
     // Allow the action (set the timer interval to what suits your needs) 
     self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 invocation:nil repeats:NO]; 

     // DO THE ACTION HERE! 
     NSLog(@"You can do it this time!"); 
    } else { 
     // Deny the action (perhaps popup an alert) 
     NSLog(@"Can't do that yet!"); 
    } 
} 
+0

它的工作真的很棒非常感謝你的快速答案! – 2013-02-10 23:06:04

+0

@CarstenGraf非常歡迎您。 – Kekoa 2013-02-10 23:07:28