一旦的NSTimer停止解雇我的目标C视图控制器

问题描述:

我使用NSTimer一旦的NSTimer停止解雇我的目标C视图控制器

timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES]; 

然后我60秒倒计时程序

-(void) updateCountdown { 
    int hours, minutes, seconds; 

    secondsLeft++; 
    hours = secondsLeft/3600; 
    minutes = (secondsLeft % 3600)/60; 
    seconds = (secondsLeft %3600) % 60; 


    time.text = [NSString stringWithFormat:@"%02d", seconds]; 

} 

我的问题是后60秒解雇我倒计时查看控制器页面..任何人都可以帮助我

+0

功能替换'重复:YES] ;'带'重复:NO];'在'NSTimer'的初始化中。 – iphonic

+0

你想在60秒后解散你的控制器或不清楚问题 –

+0

是的,我想在60秒后解雇我的视图控制器 –

如果repeats: YES];检查像你的seconds达到或大于60,无效的定时器或解散你的VC

if (seconds >60) 
{ 
[timer invalidate]; 
[self dismissViewControllerAnimated:YES completion:nil]; 
} 

别人打电话给你的计时器使用一次repeats: NO];

timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: NO]; 

,并呼吁像

-(void) updateCountdown { 
    [timer invalidate]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 

} 
+0

好的答案brother.I up voteed。 – user3182143

+0

我无法在我的方法中访问定时器,因此如何使该方法无效??安博.Karthick – Akshay

timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown:) userInfo:nil repeats: NO]; // set No 

-(void) updateCountdown:(NSTimer *)timer 
{ 
    [timer invalidate]; 
    // dismiss your controller 
}