2013-02-10 41 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