views:

72

answers:

1

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

+1  A: 

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

vodkhang
"new" isn't syntax in objc, though it is in C++ and ObjC++
jer
It is a syntax of objc, according to Apple's NSObject Reference : http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSObject_Class/Reference/Reference.html
vodkhang
This method is a combination of alloc and init. Like alloc, it initializes the isa instance variable of the new object so it points to the class data structure. It then invokes the init method to complete the initialization process.
vodkhang