刷新弹出窗口中的值

时间:2017-04-24 17:38:19

标签: ios objective-c

我在Popover中创建了倒计时。倒计时持续1分钟。问题是当我显示弹出窗口时,倒计时总是重置为1分钟并重复倒计时。

我在viewdidload方法中执行[self setimer]。

-(void)countdown{

 seconds = seconds - 1;
 static int minutes;
 minutes = seconds / 60;
 static int secondes;
  secondes = seconds - (minutes * 60);

 NSString *timeroutput = [NSString stringWithFormat:@"%2.d:%2d", minutes, secondes];
 countdown_label.text = timeroutput;

 if (seconds == 0) {
    [countdown_timer invalidate];
    countdown_timer = nil;

 }
}

-(void) setTimer{
    seconds = 1500;
    countdown_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countdown) userInfo:nil repeats:YES];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

NSString *identifier = segue.identifier;
if ([identifier isEqualToString:@"popover_time"]) {
    UIViewController *dvc = segue.destinationViewController;
    UIPopoverPresentationController *ppc = dvc.popoverPresentationController;
    if (ppc) {
        if ([sender isKindOfClass:[UIButton class]]) { // Assumes the popover is being triggered by a UIButton
            ppc.sourceView = (UIButton *)sender;
            ppc.sourceRect = [(UIButton *)sender bounds];
        }
        ppc.delegate = self;
    }

}

}

0 个答案:

没有答案