在从 UIPickerView 选择的 NSTimer 的 UILabel 中显示秒数

Display seconds in a UILabel from a NSTimer which was selected from UIPickerView

如何在 NSTimer 的标签中显示秒数?

imageVC.h

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

imageVC.m

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


        imageViewController *pickerView = [[imageViewController alloc] init];
            [NSTimer scheduledTimerWithTimeInterval:10
                                             target:self
                                           selector:@selector(timeout)
                                           userInfo:nil
                                            repeats:NO];
        }];

        }
    }

如有任何帮助,我们将不胜感激。

谢谢

尝试将超时值设置为您想要的最大值。

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

-(void) timeout {
if (timeCount==0) {
    [timer invalidate];

} else {
    timeCount = timeCount-1;
    timeLabel.text = [NSString stringWithFormat:@"%d",timeCount];
       }
 }

添加另一个间隔为 1 秒的计时器来更新标签

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


                    imageViewController *pickerView = [[imageViewController alloc] init];
                        [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timeout) userInfo:nil repeats:NO];
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(setTimeToLabel) userInfo:nil repeats:NO];
    }
- (void)setTimeToLabel
{
     counterPrivateVar += 1;
     self.lbl.text = [NSString stringWithFormat:@"%d", counter];
}