Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePicker in Timer Mode - How to get the value

I'm trying to get a datepicker in countdowntimer mode to simply allow me to select minutes and seconds and then get that value when you click a button. I set up the picker in IB and use this code, but the result is always Null when I select any combination of minutes and hours and click the button...Obviously I'm missing something. Any help on getting this to work would be appreciated.

@interface ThisPicker : UIViewController {

IBOutlet UIDatePicker *datePicker;

}

-(IBAction)buttonPressed:(id)sender;

@end

@implementation ThisPicker

-(IBAction)buttonPressed:(id)sender{

    datePicker = [[UIDatePicker alloc] init];
    datePicker.datePickerMode = UIDatePickerModeCountDownTimer;

    NSLog(@"%@",[datePicker countDownDuration]);

  }

  @end
like image 593
Allen Avatar asked Dec 13 '10 16:12

Allen


2 Answers

If you want in a Hour Minute format

-(IBAction)buttonPressed:(id)sender
  {


    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"HH:mm:ss"];
    NSLog(@"%@",[dateformatter stringFromDate:[datePicker date]]);

  }
like image 151
ipraba Avatar answered Sep 28 '22 08:09

ipraba


I believe that countDownDuration is a double.

Try accessing it this way:

NSLog(@"%f", datePicker.countDownDuration);

Edit: What you need to do is link your date picker in IB with the one in code and don't alloc it as it's causing an erase of your data.

Edit2: BuildSucceeded beat me to it. :)

like image 38
sudo rm -rf Avatar answered Sep 28 '22 09:09

sudo rm -rf