实际上使用UIDatePickerModeCountDownDownTimer作为计时器 [英] Actually using UIDatePickerModeCountDownTimer as a timer

查看:143
本文介绍了实际上使用UIDatePickerModeCountDownDownTimer作为计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想做一个计时器.我想使用UIDatePickerUIDatePickerModeCountDownTimer模式,以便当用户在选择器中简单地选择说15分钟时,它们将被传递回屏幕,该屏幕在标签中显示15分钟的值,然后他们可以倒数.

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.

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

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.

我正在尝试从UIActionSheet中显示的DatePicker传回此数据...对正在发生的事情或我做错了什么的任何想法?

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!!!!!!!

推荐答案

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

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;

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

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

这篇关于实际上使用UIDatePickerModeCountDownDownTimer作为计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆