处理iOS逻辑

时间:2015-01-27 07:15:27

标签: ios xcode

我似乎无法在同一个.m文件中使用两个NSTimer元素。我试图在时钟达到0时执行下面的第一个if语句,然后在执行代码块后仅3秒在同一个地方启动另一个定时器。在那3秒之后,我只想使用以下segue [self performSegueWithIdentifier:@"someIdentifier" sender:self];

- (void)setupGame{
seconds = 6;
timerLabel.text = [NSString stringWithFormat:@" %i",seconds];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(subtractTime) userInfo:nil repeats:YES];
}
 - (void)subtractTime{
seconds--;
timerLabel.text = [NSString stringWithFormat:@" %i",seconds];
if(seconds == 0){
    [timer invalidate];
    label.text = [NSString stringWithFormat:@"+done!"];
    timerLabel.text = [NSString stringWithFormat:@"!"];
    label2.text = [NSString stringWithFormat:@"+success! redirecting..."];
    }
}
//need a new method!

有人可以给我写一个方法来处理这个逻辑吗?

fixed * thanks =)

- (void)viewDidAppear:(BOOL)animated 
{
 [super viewDidAppear:animated];

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self performSegueWithIdentifier:@"someIdentifier" sender:self];
});
}

感谢延迟提示How to Perform Segue With Delay

0 个答案:

没有答案