实际上使用 UIDatePickerModeCountDownTimer 作为计时器

发布于 2024-09-19 18:51:26 字数 535 浏览 2 评论 0原文

我只是想制作一个计时器。我想使用 UIDatePickerUIDatePickerModeCountDownTimer 模式,这样当用户只需在选择器中选择 15 分钟时,它们就会传回显示该值的屏幕标签中包含 15 分钟,然后他们可以从中倒计时。

当我尝试从 DatePicker 获取值时,我意识到选择器会传回一个 NSTimeInterval ,该值以秒为单位获取当前时间:

UIDatePicker *pickerView = [[UIDatePicker alloc] init];
NSTimeInterval new = (NSTimeInterval)pickerView.countDownDuration;

所以我想要的就是知道用户选择的值,不是当前时间(以秒为单位)。

我正在尝试从 UIActionSheet 中呈现的 DatePicker 传回此数据...对正在发生的事情或我做错了什么有什么想法吗?

我只想要一个计时器!!!!!!!

I am just trying to make a timer. I would like to use UIDatePickerModeCountDownTimer mode of the UIDatePicker, so that when the user simply selects say 15 mins in the picker, they are passed back to a screen that shows the value of 15 mins in a label that they can then count down from.

As I have tried to get the value from the DatePicker, I realized that the picker passes back an NSTimeInterval that gets the current time in seconds:

UIDatePicker *pickerView = [[UIDatePicker alloc] init];
NSTimeInterval new = (NSTimeInterval)pickerView.countDownDuration;

So all I want is to know the value that the user selected, not the current time in seconds.

I am trying to pass this data back from a DatePicker that is being presented in a UIActionSheet...any thoughts about what is going on or what I am doing wrong?

I just want a timer!!!!!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁对谁错谁最难过 2024-09-26 18:51:26

您的代码缺少一行,您必须为 UIDatePicker 设置模式。完整的代码应该是:

UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeCountDownTimer;

// please DON'T use new because it is objc syntax
NSTimeInterval timeInterval = (NSTimeInterval)pickerView.countDownDuration;

然后如果您不知道如何将 NSTimeInterval (秒)转换为分钟,您可以使用 这个问题

Your code lacks a line, you have to set the mode for your UIDatePicker. The full code should be:

UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeCountDownTimer;

// please DON'T use new because it is objc syntax
NSTimeInterval timeInterval = (NSTimeInterval)pickerView.countDownDuration;

and then if you don't know how to convert your NSTimeInterval (seconds) to minutes, you can use this question

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文